首页 > 其他 > 详细

Math.ceil()、Math.floor()和Math.round()

时间:2018-04-16 17:06:12      阅读:166      评论:0      收藏:0      [点我收藏+]

下面来介绍将小数值舍入为整数的几个方法:Math.ceil()、Math.floor()和Math.round()。


这三个方法分别遵循下列舍入规则:
Math.ceil()执行向上舍入,即它总是将数值向上舍入为最接近的整数;
Math.floor()执行向下舍入,即它总是将数值向下舍入为最接近的整数;
Math.round()执行标准舍入,即它总是将数值四舍五入为最接近的整数(这也是我们在数学课上学到的舍入规则)。

技术分享图片

Math.ceil()、Math.floor()和Math.round()

原文:https://www.cnblogs.com/newcaoguo/p/8856612.html

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