Home >>JavaScript Math Reference >JavaScript round() Method

JavaScript round() Method

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 Values

Parameter Description
x It required the number to be rounded

Browser Support

Method Chrome Edge Firefox Safari Opera
round() Yes Yes Yes Yes Yes
Here is an example of JavaScript round() Method :
<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>
Output:

Example 2:
<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>
Output: