Math.round() method in Javascript.
How to round a number to the nearest integer in javascript?
Explanation
Math Function:
Object: Math
Method: Math.round()
Description:
This function is used for rounding a number to the nearest integer.
For an example we will try to round the log value of 2.
Example for rounding a number:
<script type="text/javascript">
var a=Math.log(2);
document.write('Log of 2 is::'+a);
document.write('</br>');
var b=Math.round(a);
document.write('The rounded value is::'+ b);
</script> Result:
In the above example,
The log value of 2 is actually "0.6931" .
Math.round() method is used for rounding the number to the nearest integer ie., "1".
A Note
Javascript (JS) is one of the most used languages in the world. Some times spelled as Java Script.
Hope you enjoy this tutorial. Do send your feedback or suggestions on this javascript or java script tutorial. This is a copyright content.