Name
Math.round( ) Method — calculate the closest integer to a number
Availability
Flash 5; may be used when exporting Flash 4 movies
Synopsis
Math.round(x)
Arguments
- x
A number.
Returns
The integer mathematically closest to x
(or x
itself, if
x
is an integer). If the fractional
component of x
is exactly 0.5
(x
is equidistant from the two closest
integers), round( )
returns the first integer
greater than x
.
Description
The round( )
method performs traditional
rounding; it converts a floating-point number to the nearest integer.
Positive numbers with a fractional portion less
than 0.5 and negative numbers with a fractional portion
greater than 0.5 are rounded
down. Positive numbers with a fractional portion
greater than or equal to 0.5 and negative
numbers with a fractional portion less than or
equal to 0.5 are rounded up.
Example
Math.round(1.4); // Returns 1 Math.round(1.5); // Returns 2 Math.round(1.6); // Returns 2 Math.round(-5.4); // Returns -5 Math.round(-5.5); // Returns -5 Math.round(-5.6); // Returns -6
See Also
int( )
, Math.ceil( )
,
Math.floor( )
Get ActionScript: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.