int( ) Global Function

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
int( ) Global Function Flash 4; deprecated in Flash 5 in favor of analogous Math methods

truncate the decimal portion of a number
int(number)

Arguments

number

A number or an expression that yields a number, typically with a fractional (decimal) portion.

Returns

The integer portion of number.

Description

The int( ) function was used in Flash 4 to extract the integer portion of a number. It effectively rounds positive numbers down and rounds negative numbers up. The int( ) function works only for numbers in the range -2147483648 (-231) to 2147483647 (231-1); it produces undefined results for numbers outside this range. If number is a string composed of only numbers, int( ) converts the string to a number before operating on it. If number is the Boolean value true, int( ) returns the value 1. For all other nonnumeric data (including undefined and null), int( ) returns the value 0.

Usage

The int( ) function has been deprecated in favor of the more precise and standard Math.floor( ), Math.ceil( ), and Math.round( ) methods. Use parseInt( ) or Number( ) to convert nonnumeric data to an integer or number.

Example

int(4.5)      // Yields 4 int(-4.5)     // Yields -4 int(3.999)    // Yields 3

The int( ) function is useful to check if a number is a whole number, by comparing the original number to the result of the int( ) function:

if (int(x) != x) {   trace("Please enter a whole number for your age in years"); }

See Also

Math.ceil( ), Math.floor( ), Math.round( ), Number( ), parseFloat( ), parseInt( )



    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