Name
Number.toString( ) Method — convert a Number to a string
Availability
Flash 5
Synopsis
numberObject.toString(radix)
Arguments
- radix
An integer between 2 and 36 specifying the base of the number system used to represent
numberObjectin string format. This argument is optional; if omitted, it defaults to 10.
Returns
The value of numberObject converted to a
string.
Description
The toString( ) method retrieves the value of a
Number object, converts that value to a string,
and returns that string. We may use the
radix argument to convert numeric values
between different bases (e.g., binary, octal, decimal, and
hexadecimal). The letters A-Z are used to represent digits with the
value 10-35, respectively, although ordinarily only A through F are
used (to represent the hex digits equivalent to 10 through 15).
To use Number.toString( ) with a primitive
numeric value, surround the value with parentheses, as in:
(204).toString(16);
Example
x = new Number(255); trace(x.toString( )); // Displays: "255" (i.e., decimal) trace(x.toString(16)); // Displays: "ff" (i.e., hexadecimal) trace(x.toString(2)); // Displays: "11111111" (i.e., binary) // Convert a hex literal to decimal trace((0xFFFFFF).toString(10)); // Displays: "16777215"
See Also
Number ( ), Object.toString(
), parseInt( ); See Section 4.3.1 in Chapter 4
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access