Home >>JavaScript Math Reference >JavaScript round() Method
JavaScript math round() method in JavaScript is used to return the value of a number rounded to its nearest integer. The argument is rounded to the next higher integer when the decimal (fractional) part of the number is greater than or equal to 0.5 and the argument is rounded to the next lower integer when the decimal (fractional) part of the number is less than 0.5.
Syntax:Math.round(var);
Parameter | Description |
---|---|
x | It required the number to be rounded |
Method | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
round() | Yes | Yes | Yes | Yes | Yes |
<html> <body> <button onclick="myround()">Click me</button> <p id="round"></p> <script> function myround() { document.getElementById("round").innerHTML = Math.round(5.5); } </script> </body> </html>
<html> <body> <script type="text/javascript"> var x =Math.round(-14.5); document.write("Number after rounding : " + x + "<br>"); var x =Math.round(14.51); document.write("Number after rounding : " + x); </script> </body> </html>