Math.round() method in JavaScript

In JavaScript math.round() method rounds a number to its nearest integer value.
Suppose If the fractional portion of the number is .5 or greater, the result is rounded to the next highest integer and if the fractional portion of number is less than .5, the result is rounded to the next lowest integer. for example rounding value of 2.6 is 3 and rounding value of 2.4 is 2.

In negative numbers, if the decimal portion is exactly -0.5, the return value is the smallest integer that is greater than the number.For example, Math.round(5.5) returns 6, but Math.round(-5.5) returns -5.

You can use round() method as :

Math.round(number)
where number is the number for which the absolute value is needed

Example 1

In this example we divide 25 to 4, we know that the exact result will be 6.25 but when we use round() function then result will be 6. see below:

<html>
<head>
<title>round method</title>
</head>
 <body >
    <script type="text/javascript">
        var number1 = 25;
        var number2 = 4;
        var result ;
        result = number1 / number2;
        document.write(Math.round(result));
    </script>
 </body>
</html>

Example 2

See another example with output:

   <HEAD>
   <TITLE>
       use of round function in javaScript
   </TITLE>
   </HEAD>
   <BODY>
    <script type="text/javascript">
	document.write(Math.round(16.84) + "<br />");
	document.write(Math.round(.50) + "<br />");
	document.write(Math.round(0.48) + "<br />");
	document.write(Math.round(-2.46) + "<br />");
	document.write(Math.round(-9.51)+ "<br />");
	document.write(Math.round(9.51));
    </script>
   </BODY>
</HTML>

Output will be:
17
1
0
-2
-10
10