Core JavaScript 1.5 Reference:Global Objects:Math:round
From MDC
Contents |
[edit] Summary
Returns the value of a number rounded to the nearest integer.
| Method of Math | |
|
Static |
|
| Implemented in: | JavaScript 1.0, NES 2.0 |
| ECMA Version: | ECMA-262 |
[edit] Syntax
Math.round(x)
[edit] Parameters
-
x - A number.
[edit] Description
If the fractional portion of number is .5 or greater, the argument is rounded to the next higher integer. If the fractional portion of number is less than .5, the argument is rounded to the next lower integer.
Because round is a static method of Math, you always use it as Math.round(), rather than as a method of a Math object you created.
[edit] Examples
[edit] Example: Using Math.round
//Returns the value 20 x=Math.round(20.49) //Returns the value 21 x=Math.round(20.5) //Returns the value -20 x=Math.round(-20.5) //Returns the value -21 x=Math.round(-20.51)