Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

JavaScript: Rounding float values

‘floor’, ‘ceil’, ‘round’ functions are used to perform Rounding on float values.

Function
Description
Math.floor(number)
Get the floor value of a number.
Math.ceil(number)
Get the ceil value of a number.
Math.round(number)
Round the number to nearest integer.

var a = Math.floor(5.9);         // Return 5
var b = Math.ceil(5.1);          // Return 6
var c = Math.round(5.4);       // Return 5
var d = Math.round(5.5);       // Return 6

round.html






rounding example



"text/javascript">
var a = Math.floor(5.9); // Return 5
var b = Math.ceil(5.1); // Return 6
var c = Math.round(5.4); // Return 5
var d = Math.round(5.5); // Return 6

document.write("a = " + a + "
"
);
document.write("b = " + b + "
"
);
document.write("c = " + c + "
"
);
document.write("d = " + d + "
"
);






Previous                                                 Next                                                 Home


This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

JavaScript: Rounding float values

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×