Math.round( ) Method | Flash 5; can be used when exporting Flash 4 movies |
calculate the closest integer to a number |
A number.
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.
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.
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
int( ), Math.ceil( ), Math.floor( )