Math.round() Function

Math.round() method in Javascript.
How to round a number to the nearest integer in javascript?


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.


<script type="text/javascript">
var a=Math.log(2);
document.write('Log of 2 is::'+a);
var b=Math.round(a);
document.write('The rounded value is::'+ b);


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".

Ask Questions

Ask Question