Math.round(x)函数

round函数语法

Math.round(x);

round函数参数

  • x -- 为number类型的数字

round函数返回值

返回x最接近的整数,如果x的小数部分大于等于0.5,返回值是大于x的最小整数,否则round函数返回小于等于x的最大整数

round函数示例

document.write(Math.round(5.8));
document.write(Math.round(5.2));
document.write(Math.round(-5.8));
document.write(Math.round(-5.2));

结果:

6
5
-6
-5
原文地址:https://www.cnblogs.com/MikeYao/p/1596114.html