首页 > Web开发 > 详细

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

时间:2017-06-13 15:09:15      阅读:256      评论:0      收藏:0      [点我收藏+]
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。

 

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

原文:http://www.cnblogs.com/cnundefined/p/7000691.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!