Number.prototype.toString()

  • Revision slug: JavaScript/Reference/Global_Objects/Number/toString
  • Revision title: toString
  • Revision id: 61403
  • Created:
  • Creator: evilpie
  • Is current revision? No
  • Comment 5 words added, 12 words removed

Revision Content

Returns a string representing the specified Number object

Method of Number
Implemented in 1.1
ECMAScript Edition ECMAScript 1st Edition

Syntax

number.toString( {{ mediawiki.external('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"

See Also

{{ languages( { "es": "es/Referencia_de_JavaScript_1.5/Objetos_globales/Number/toString", "ja": "ja/Core_JavaScript_1.5_Reference/Global_Objects/Number/toString", "pl": "pl/Dokumentacja_j\u0119zyka_JavaScript_1.5/Obiekty/Number/toString" } ) }}

Revision Source

<p>
</p>
<p>Returns a string representing the specified Number object
</p>
<table class="standard-table"> <thead> <tr> <th class="header" colspan="2">Method of <a href="/en/JavaScript/Reference/Global_Objects/Number"><code>Number</code></a></th> </tr> </thead> <tbody> <tr> <td>Implemented in</td> <td>1.1</td> </tr> <tr> <td>ECMAScript Edition</td> <td>ECMAScript 1st Edition</td> </tr> </tbody>
</table> <h3 name="Syntax"> Syntax </h3>
<p><code><i>number</i>.toString( {{ mediawiki.external('<i>radix</i>') }} )</code>
</p>
<h3 name="Parameter"> Parameter </h3>
<dl><dt> radix
</dt><dd> An integer between 2 and 36 specifying the base to use for representing numeric values.
</dd></dl>
<h3 name="Description"> Description </h3>
<p>The <code>Number</code> object overrides the <code>toString</code> method of the <code><a href="en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></code> object; it does not inherit <code><a href="en/Core_JavaScript_1.5_Reference/Global_Objects/Object/toString">Object.toString</a></code>. For <code>Number</code> objects, the <code>toString</code> method returns a string representation of the object in the specified radix.
</p><p>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.
</p><p>If toString is given a radix not between 2 and 36, an exception is thrown.
</p><p>If the radix is not specified, JavaScript assumes the preferred radix is 10.
</p>
<h3 name="Examples"> Examples </h3>
<pre class="eval">var count = 10;
print(count.toString());   // displays "10"
print((17).toString());    // displays "17"

var x = 7;
print(x.toString(2));      // displays "111"
</pre>
<h3 name="See_Also"> See Also </h3>
<ul><li><a href="en/Core_JavaScript_1.5_Reference/Global_Objects/Number/toExponential">Number.prototype.toExponential</a>
</li><li><a href="en/Core_JavaScript_1.5_Reference/Global_Objects/Number/toLocaleString">Number.prototype.toLocaleString</a>
</li><li><a href="en/Core_JavaScript_1.5_Reference/Global_Objects/Number/toPrecision">Number.prototype.toPrecision</a>
</li><li><a href="en/Core_JavaScript_1.5_Reference/Global_Objects/Number/toFixed">Number.prototype.toFixed</a>
</li><li><a href="en/Core_JavaScript_1.5_Reference/Global_Objects/Number/toSource">Number.prototype.toSource</a>
</li><li><a href="en/Core_JavaScript_1.5_Reference/Global_Objects/Number/valueOf">Number.prototype.valueOf</a>
</li></ul>
<div class="noinclude">
</div>
{{ languages( { "es": "es/Referencia_de_JavaScript_1.5/Objetos_globales/Number/toString", "ja": "ja/Core_JavaScript_1.5_Reference/Global_Objects/Number/toString", "pl": "pl/Dokumentacja_j\u0119zyka_JavaScript_1.5/Obiekty/Number/toString" } ) }}
Revert to this revision