JavaScript & jQuery Tutorials

JS Home Right Arrow JS Reference Right Arrow Number Right Arrow toString()

toString()  Number  instance method

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
radixThe optional radix (number base) that pertains to the string value specified.
  • The radix must be in the range 2-26 or an exception is thrown.
  • When no radix is specified, the decimal number base is assumed (radix set to 10).

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);

Press the button below to action the above code:



Related Tutorials

JavaScript Advanced Tutorials - Lesson 3 - Number




  

go to home page Homepage go to top of page Top