Home > Article > Web Front-end > What does round mean in javascript
In JavaScript, the round() method means to round a number. This method can round a number to the nearest integer. The returned result is the rounded result. The syntax is "Math .round(number)".
The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
The round() method can round a number to the nearest integer.
Note: 2.49 will be rounded to 2, 2.5 will be rounded to 3.
The round() method is supported by all major browsers
Syntax
Math.round(x)
x Required. Must be a number.
The example is as follows:
<html> <head> <meta charset="utf-8"> <title>123</title> </head> <body> <p id="demo">单击按钮舍入与“2.5”最接近的整数</p> <button onclick="myFunction()">点我</button> <script> function myFunction(){ document.getElementById("demo").innerHTML=Math.round(2.5); } </script> </body> </html>
Output result:
After clicking the button:
Related recommendations: javascript learning tutorial
The above is the detailed content of What does round mean in javascript. For more information, please follow other related articles on the PHP Chinese website!