JavaScript round() method
Example
The round() method rounds a number to the nearest integer:
Math.round(2.5);
Output result:
3
Try it »
Definition and Usage
The round() method rounds a number to the nearest integer.
Note: 2.49 rounds to 2 and 2.5 rounds to 3.
Browser support





All major browsers support the round() method
Syntax
Math.round(
x
)
Parameter value
| Parameters | Description |
|---|---|
| x | Required. Must be a number. |
Return Value
| Type | Description |
|---|---|
| Number | The nearest integer. |
Technical Details
| JavaScript version: | 1.0 |
|---|
More examples
Example
Round different numbers to the nearest integer:
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);
a,b,c,d,e, and LinkedHashMap, among others. f Output result:
3
3
2
-3
-2
-2
Try it »
JavaScript Math object