SQL PHP HTML ASP JavaScript articles and free scripts to download
 

Math Round function in JavaScript

We can round off any number with decimal place to an integer value by using round function. If the decimal portion of the number is equal or greater than .5 then the next higher integer is returned or if the number is less than 05 then the number is rounded to next lowest integer.

Here is the syntax.


Math.round(number)



Here are some examples.



document.write (Math.round(2.65));// print 3
document.write (Math.round(7.05));// print 7
document.write (Math.round(-2.65));// print -3
document.write (Math.round(-8.15));// print -8
document.write (Math.round(11.65));// print 12


We can format math number by using round function. Here is an example to format upto two decimal places.
var my_val=11.257;
var my_val=11.254;

document.write (Math.round(my_val*100)/100);


But we can use math toFixed function to format any number

You can read the php math round function













Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked


Join Our Email List
Email:  
For Email Newsletters you can trust
Math functions