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

JavaScript Basics

JavaScript Basics

JavaScript Intermediate

JavaScript Intermediate

JavaScript Advanced

JavaScript Advanced

JavaScript Reference

JavaScript Entities

Globals

Number

MIN_VALUE
NaN
NEGATIVE_INFINITY
POSITIVE_INFINITY
prototype
Instance Properties
constructor
Class Methods
None.
Instance Methods Getters
toExponential()
toFixed()
toLocaleString()
toPrecision()
toString()
valueOf()
Instance Methods Setters
None.

Statements

Operators