本文转自:http://blog.sina.com.cn/s/blog_7e4815650100wrfz.html
JavaScript: The Definitive Guide, 4thEdition中对Math.ceil(),Math.floor()与Math.round()三个函数的定义。
Math.random()
| 返回 0 ~ 1 之间的随机数。 |
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));

JavaScript数学函数详解:Math.ceil(), Math.floor()与Math.round()
本文详细介绍了JavaScript中Math.ceil(), Math.floor()与Math.round()三个数学函数的用法及特性,通过实例展示了如何使用这些函数进行数值的四舍五入操作。
933

被折叠的 条评论
为什么被折叠?



