在javascript中过多的圆数

Cap*_*vez 0 javascript rounding

在Javascript中是否有任何方法可以将数字舍入过多,例如:

5.3 = 6

10.7 = 11

1.1 = 2

就像每次逗号后的数字大于0时,我们将数字向上舍入.

提前致谢

Poi*_*nty 7

它被称为Math.ceil():

var x = 5.3;
alert(Math.ceil(x)); // 6
Run Code Online (Sandbox Code Playgroud)

名称"ceil"是"ceiling"的缩写.相反的功能是Math.floor().这两种功能都按照幅度运行.有时候,你想要"远离零"或"向零"工作,所以你必须特别检查.(即Math.ceil(-2.1)-2,而不是-3.)