JavaScript Math.round()
Examples
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 »
Description
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).
JavaScript Rounding Functions
The Math.abs() MethodThe Math.ceil() Method
The Math.floor() Method
The Math.round() Method
The Math.fround() Method
The Math.trunc() Method
Syntax
Math.round(x)
Parameters
Parameter | Description |
x | Required. A number. |
Return Value
Type | Description |
Number | The number rounded to the nearest integer. |
Browser Support
Math.round()
is an ECMAScript1 (JavaScript 1997) feature.
It is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |