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

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

Math.ceil()

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

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

Math.floor()

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

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

Math.round()

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

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

 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));

Math的Ceil,Floor,Round三个函数

相关文章
相关标签/搜索