码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-04-16 18:34:24      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:com   技术分享   img   规则   小数   png   ima   .com   数值   

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


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

技术分享图片

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

标签:com   技术分享   img   规则   小数   png   ima   .com   数值   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!