JavaScript round() 方法
- Vorherige Seite random()
- Nächste Seite sign()
- Zurück zur vorherigen Ebene JavaScript Math Referenzhandbuch
定义和用法
round()
方法将数字四舍五入到最接近的整数。
注释:2.49 将向下舍入 (2),而 2.5 将向上舍入 (3)。
说明
对于 0.5,该方法将进行上舍入。
例如,3.5 将舍入为 4,而 -3.5 将舍入为 -3。
实例
例子 1
将数字四舍五入到最接近的整数:
Math.round(2.5);
例子 3
将不同的数字四舍五入到最接近的整数:
var a = Math.round(2.60); var b = Math.round(2.50); var c = Math.round(2.49); var d = Math.round(-2.60); var e = Math.round(-2.50); var f = Math.round(-2.49);
语法
Math.round(x)
参数值
参数 | 描述 |
---|---|
x | 必需。要四舍五入的数字。 |
技术细节
返回值: | Zahl, die den nächstgelegenen Ganzen Wert angibt. |
---|---|
JavaScript-Version: | ECMAScript 1 |
Browser-Unterstützung
Methode | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
round() | Unterstützung | Unterstützung | Unterstützung | Unterstützung | Unterstützung |
Verwandte Seiten
Tutorial:JavaScript-Mathematik
- Vorherige Seite random()
- Nächste Seite sign()
- Zurück zur vorherigen Ebene JavaScript Math Referenzhandbuch