Math.round( ) Method

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
Math.round( ) Method Flash 5; can be used when exporting Flash 4 movies

calculate the closest integer to a number
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( )



    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net