Home  >  Article  >  Web Front-end  >  What does round mean in javascript

What does round mean in javascript

WBOY
WBOYOriginal
2022-02-07 16:32:343807browse

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

What does round mean in javascript

The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.

What does round mean in javascript

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:

What does round mean in javascript

After clicking the button:

What does round mean in javascript

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn