Home  >  Article  >  Web Front-end  >  JavaScript Math.round() 方法_javascript技巧

JavaScript Math.round() 方法_javascript技巧

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

 Math.round()方法的定义和用法:

Math.round()方法将对参数进行四舍五入操作。

点击可参阅更多相关Math对象方法和属性。

语法结构:

Math.round(x)

参数列表:

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

实例代码:

实例一:

复制代码 代码如下:

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

输出结果:-2。

实例二:

复制代码 代码如下:

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

输出结果:-3。

实例三:

复制代码 代码如下:

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

输出结果:3。

以上内容是小编给大家介绍的JavaScript Math.round() 方法的全部叙述,希望大家喜欢。

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