floor(x) 返回不大于的最大整数(结果数值<=x);
Math.round (x)则是4舍5入的计算,算法为Math.floor(x+0.5),即将原来的数字加上0.5后再向下取整,入的时候是到大于它的整数.(结果数值<=x+0.5);
ceil (x)则是不小于他的最小整数.(结果数值>=x);
看例子:
floor Math.round ceil
0.9 0 1 1
1.4 1 1 2
2 2 2 2
-0.9 -1 -1 0
-1.4 -2 -1 -1
版权声明:本文为博主自己原创文章,未经博主允许不得转载。