js 中的 Math.ceil() Math.floor Math.round()

alert(Math.ceil(25.9)); //26
alert(Math.ceil(25.5)); //26
alert(Math.ceil(25.1)); //26
alert(Math.round(25.9)); //26
alert(Math.round(25.5)); //26
alert(Math.round(25.1)); //25
alert(Math.floor(25.9)); //25
alert(Math.floor(25.5)); //25
alert(Math.floor(25.1)); //25

对于所有介于25和26(不包括26)之间的数值,Math.ceil()始终返回26,因为它执行的是向上舍入。

Math.round()方法只在数值大于等于25.5时返回26;否则返回25。

最后,Math.floor()对所有介于25和26(不包括26)之间的数值都返回25。

原文地址:https://www.cnblogs.com/cnundefined/p/7000691.html