toString()
Number
instance method
JS Home <<
JS Reference <<
Number <<
toString()
Description
Returns a string representation of the numeric value.
This method overrides the toString()
method of Object
.
Syntax
Signature | Description |
---|---|
aNumber.toString([radix]) | Returns a string representation of the numeric value. |
Parameters
Parameter | Description |
---|---|
radix | The optional radix (number base) that pertains to the string value specified.
|
Examples
The code below displays some numerical values as strings.
// Create an array for strings and populate.
var aNumber = 16;
var stringValue = new Array(4);
stringValue[0] = aNumber.toString(); // Decimal default
stringValue[1] = aNumber.toString(2); // Binary
stringValue[2] = aNumber.toString(8); // Octal
stringValue[3] = aNumber.toString(16); // Hex
alert(stringValue);
Related Tutorials
JavaScript Advanced Tutorials - Lesson 3 - Number