Math.round() Function
Math.round() method in Javascript.
How to round a number to the nearest integer in javascript?
Explanation
Math Function:Object:
MathMethod:
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:
<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".