Math.ceil(),Math.floor()与Math.round()三个函数的定义。

。_饼干妹妹 提交于 2019-12-05 19:41:10

JavaScript: The Definitive Guide, 4th Edition中对Math.ceil(),Math.floor()与Math.round()三个函数的定义。

Math.ceil()

ceil() 方法可对一个数进行上舍入。

参数必须是一个数值。返回值大于等于 x,并且与它最接近的整数。

Math.floor()

floor() 方法可对一个数进行下舍入。

参数可以是任意数值或表达式。返回值小于等于 x,且与 x 最接近的整数。

Math.round()

round() 方法可把一个数字舍入为最接近的整数

参数必须是一个数值。返回值与 x 最接近的整数。

 document.writeln("Math.ceil(4.8992303)输出结果:"+Math.ceil(4.8992303)+"<br/>"); document.writeln("Math.floor(4.8992303)输出结果:"+Math.floor(4.8992303)+"<br/>"); document.writeln("Math.round(4.8992303)输出结果:"+Math.round(4.8992303)+"<br/><br/>"); document.writeln("Math.ceil(4.29993354)输出结果:"+Math.ceil(4.29993354)+"<br/>"); document.writeln("Math.floor(4.29993354)输出结果:"+Math.floor(4.29993354)+"<br/>"); document.writeln("Math.round(4.29993354)输出结果:"+Math.round(4.29993354));  

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!