- ceil的意思是天花板,表示向上取整,例如Math.ceil(5.2)的结果为6,Math.ceil(-5.8)的结果为-5
- floor的意思是地板,表示向下取整,例如Math.floor(5.2)的结果为5,Math.floor(-5.8)的结果为-6
- round表示四舍五入取整,算法为Math.round(x+0.5),即将原来的数字加上0.5再向下取整,
例如,Math.round(5.2)的结果为5,Math.round(-5.8)的结果为-6,Math.round(-5.2)的结果为-5
Math类中3个取整方法(ceil、floor、round)
最新推荐文章于 2021-05-23 14:16:37 发布