User Guide
74 ActionScript language elements
Example
The following examples use the parseFloat() function to evaluate various types of numbers:
trace(parseFloat("-2")); // output: -2
trace(parseFloat("2.5")); // output: 2.5
trace(parseFloat(" 2.5")); // output: 2.5
trace(parseFloat("3.5e6")); // output: 3500000
trace(parseFloat("foobar")); // output: NaN
trace(parseFloat("3.75math")); // output: 3.75
trace(parseFloat("0garbage")); // output: 0
See also
NaN constant, parseInt function
parseInt function
parseInt(expression:String [, radix:Number]) : Number
Converts a string to an integer. If the specified string in the parameters cannot be converted to
a number, the function returns
NaN. Strings beginning with 0x are interpreted as hexadecimal
numbers. Integers beginning with 0 or specifying a radix of 8 are interpreted as octal numbers.
White space preceding valid integers is ignored, as are trailing nonnumeric characters.
Availability: ActionScript 1.0; Flash Lite 2.0
Parameters
expression:String - A string to convert to an integer.
radix:Number [optional] - An integer representing the radix (base) of the number to parse.
Legal values are from 2 to 36.
Returns
Number - A number or NaN (not a number).
Example
The examples in this section use the parseInt() function to evaluate various types of
numbers.
The following example returns 3:
parseInt("3.5")
The following example returns NaN:
parseInt("bar")