[Javascript] Math ceil()、floor()、round()三个函数的区别
概述:
1. round是四舍五入的
2. ceiling是向上取整
3. float是向下取整
舍入规则:
1. Math.ceil()执行向上舍入,即它总是将数值向上舍入为最接近的整数;
2. Math.floor()执行向下舍入,即它总是将数值向下舍入为最接近的整数;
3. Math.round()执行标准舍入,即它总是将数值四舍五入为最接近的整数(这也是我们在数学课上学到的舍入规则)。
下面是使用这些方法的示例:
Math.ceil(25.9); //26
Math.ceil(25.5); //26
Math.ceil(25.1); //26
Math.round(25.9); //26
Math.round(25.5); //26
Math.round(25.1); //25
Math.floor(25.9); //25
Math.floor(25.5); //25
Math.floor(25.1); //25
There is no holding back time you said .
So you run your race ,made your transformation and left your mark .

浙公网安备 33010602011771号