let x = Math.round(2.5);
Try it Yourself »
let a = Math.round(2.60);
let b = Math.round(2.50);
let c = Math.round(2.49);
let d = Math.round(-2.60);
let e = Math.round(-2.50);
let f = Math.round(-2.49);
Try it Yourself »
The Math.round()
method rounds a number to the nearest integer.
2.49 will be rounded down (2), and 2.5 will be rounded up (3).
Math.round(
x)
Parameter | Description |
x | Required. A number. |
Type | Description |
Number | The number rounded to the nearest integer. |
Math.round()
is an ECMAScript1 (ES1) feature.
ES1 (JavaScript 1997) is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!