Table of Contents

Number.toString( ) Method Flash 5

convert a number to a string
numberObject.toString(radix)

Arguments

radix

An integer between 2 and 36 specifying the base of the number system used to represent numberObject in 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 instance, converts that value to a string, and returns that string. We can use the optional 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 values of 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" (string version of decimal)
trace(x.toString(16));     // Displays: "ff" (string version of hexadecimal)
trace(x.toString(2));      // Displays: "11111111" (string version of binary)
   
// Convert a hex literal to a decimal string
trace((0xFFFFFF).toString(10));       // Displays: "16777215" (a string)
// Convert a hex literal to a decimal integer
x = parseInt(0xFFFFFF).toString(10)); // x equals 16777215 (a number), not "16777215"

See Also

Number( ), Object.toString( ), parseInt( ); Section 4.3.1


Table of Contents