
Object Class
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Alphabetical Language Reference
|
717
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 ordi-
narily 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 paren-
theses, 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(); “Integer Literals,” in Chapter 4
Object Class
the basis for all other classes and the basis for generic objects
Flash 5
Constructor
new Object() ...