JavaScript round() Method
- Previous Page random()
- Next Page sign()
- Go Back to Previous Level Manwal ng Reference ng JavaScript Math
Definition and Usage
round()
The method rounds a number to the nearest integer.
Comment:2.49 will be rounded down (2), while 2.5 will be rounded up (3).
Note
For 0.5, the method will perform ceiling rounding.
For example, 3.5 will be rounded to 4, and -3.5 will be rounded to -3.
Example
Example 1
Round a number to the nearest integer:
Math.round(2.5);
Example 3
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);
Syntax
Math.round(x)
Parameter Value
Parameter | Description |
---|---|
x | Required. The number to be rounded. |
Technical Details
Return Value: | Number, representing the nearest integer. |
---|---|
JavaScript Version: | ECMAScript 1 |
Browser Support
Method | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
round() | Support | Support | Support | Support | Support |
Related Pages
Tutorial:JavaScript Suanxue
- Previous Page random()
- Next Page sign()
- Go Back to Previous Level Manwal ng Reference ng JavaScript Math