JavaScript round() 方法
定义和用法
round() 方法可把一个数字舍入为最接近的整数。
语法
Math.round(x)
| 参数 | 描述 | 
|---|---|
| x | 必需。必须是数字。 | 
返回值
与 x 最接近的整数。
说明
对于 0.5,该方法将进行上舍入。
例如,3.5 将舍入为 4,而 -3.5 将舍入为 -3。
实例
把不同的数舍入为最接近的整数:
<script type="text/javascript">
document.write(
document.write(
document.write(
document.write(
document.write(
</script>
document.write(
Math.round(0.60) + "<br />")document.write(
Math.round(0.50) + "<br />")document.write(
Math.round(0.49) + "<br />")document.write(
Math.round(-4.40) + "<br />")document.write(
Math.round(-4.60))</script>
输出:
1
1
0
-4
-5
1
0
-4
-5
实例
round()
如何使用 round() 方法。
 JavaScript Math 对象参考手册