Mozilla.com

Summary

Returns a string representing the specified Number object

Method of Number
Implemented in: JavaScript 1.1
ECMA Version: ECMA-262

Syntax

number.toString( [radix] )

Parameter

radix
An integer between 2 and 36 specifying the base to use for representing numeric values.

Description

The Number object overrides the toString method of the Object object; it does not inherit Object.toString. For Number objects, the toString method returns a string representation of the object in the specified radix.

The toString method parses its first argument, and attempts to return a string representation in the specified radix (base). For radixes above 10, the letters of the alphabet indicate numerals greater than 9. For example, for hexadecimal numbers (base 16), A through F are used.

If toString is given a radix not between 2 and 36, an exception is thrown.

If the radix is not specified, JavaScript assumes the preferred radix is 10.

Examples

var count = 10;
print(count.toString());   // displays "10"
print((17).toString());    // displays "17"

var x = 7;
print(x.toString(2));      // displays "111"

Page last modified 19:08, 1 Dec 2007 by Sevenspade

Tags:

Files (0)