Home >Web Front-end >JS Tutorial >JavaScript Math.round() method_javascript tips

JavaScript Math.round() method_javascript tips

WBOY
WBOYOriginal
2016-05-16 15:24:501449browse

Definition and usage of Math.round() method:

The Math.round() method will round the parameters.

Click to see more related Math object methods and properties.

Grammar structure:

Math.round(x)

Parameter list:

参数 描述
x 必需。必须是数值类型。

Example code:

Example 1:

Copy code The code is as follows:

console.log(Math.round(-2.1));

Output result: -2.

Example 2:

Copy code The code is as follows:

console.log(Math.round(-2.9));

Output result: -3.

Example 3:

Copy code The code is as follows:

console.log(Math.round(2.9));

Output result: 3.

The above content is the entire description of the JavaScript Math.round() method introduced by the editor. I hope you like it.

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