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

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


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

posted @ 2018-04-16 16:30  newcaoguo  阅读(1585)  评论(0编辑  收藏  举报