首页 > 编程语言 > 详细

Javascript Math.ceil()与Math.round()与Math.floor()区别

时间:2015-07-26 15:29:54      阅读:256      评论:0      收藏:0      [点我收藏+]

Math.ceil()向上舍入

1
2
3
alert(Math.ceil(20.1)) //输出 21
alert(Math.ceil(20.5)) //输出 21
alert(Math.ceil(20.9)) //输出 21

 Math.round标准的四舍五入

1
2
3
alert(Math.round(20.1)) //输出 20
alert(Math.round(20.5)) //输出 21
alert(Math.round(20.9)) //输出 21

 Math.floor()向下舍入

1
2
3
alert(Math.floor(20.1)) //输出 20
alert(Math.floor(20.5)) //输出 20
alert(Math.floor(20.9)) //输出 20

 

Javascript Math.ceil()与Math.round()与Math.floor()区别

原文:http://www.cnblogs.com/xcsn/p/4677583.html

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