Name
parseInt( ) Global Function — extract an integer from a string or convert numbers to base-10.
Availability
Flash 5
Synopsis
parseInt(stringExpression) parseInt(stringExpression, radix)
Arguments
- stringExpression
The string from which an integer is to be extracted.
- radix
An optional integer, between 2 and 36, specifying the base (or radix) of the integer to be extracted. If not specified, the default radix depends on the contents of
stringExpression
(as described later).
Returns
The extracted integer value, as a base-10 number regardless of the
original radix
. Or, if extraction was
unsuccessful, the special numeric value NaN
.
Description
The parseInt( )
function converts a string
expression to an integer. It works only with strings that contain a
valid string representation of an integer using the specified radix.
The string must be of the following form:
Optional leading whitespace
Optional + or -
One or more digits that are valid in the number system of the specified radix
Trailing characters that cannot be parsed as part of the preceding numeric form are ignored.
The number derived from the supplied string starts with the first
nonblank character in the string and ends with the character before
the first character that is not a legitimate digit in the supplied
radix
. For example, in the base-10 system,
the letter F is not a valid digit, so the
following expression yields the number 2:
parseInt("2F", 10);
But in the base-16 system (hexadecimal), the characters A, B, C, D, E, and F are valid ...
Get ActionScript: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.