int( ) Global Function | Flash 4; deprecated in Flash 5 in favor of analogous Math methods |
truncate the decimal portion of a number |
A number or an expression that yields a number, typically with a fractional (decimal) portion.
The integer portion of number.
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.
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.
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"); }
Math.ceil( ), Math.floor( ), Math.round( ), Number( ), parseFloat( ), parseInt( )