MDN may have intermittent access issues April 18 13:00 - April 19 01:00 UTC. See whistlepig.mozilla.org for all notifications.

mozilla

Revision 61402 of Number.prototype.toString()

  • Revision slug: JavaScript/Reference/Global_Objects/Number/toString
  • Revision title: toString
  • Revision id: 61402
  • Created:
  • Creator: Sevenspade
  • Is current revision? No
  • Comment formatting; revise example; remove redundant /* Returns */ section

Revision Content

Summary

Returns a string representing the specified Number object

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

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>
<h3 name="Summary"> Summary </h3>
<p>Returns a string representing the specified Number object
</p>
<table class="fullwidth-table">
<tbody><tr>
<td class="header" colspan="2">Method of <a href="en/Core_JavaScript_1.5_Reference/Global_Objects/Number">Number</a></td>
</tr>
<tr>
<td>Implemented in:</td>
<td>JavaScript 1.1<span class="comment">, JScript 2</span></td>
</tr>
<tr>
<td>ECMA Version:</td>
<td>ECMA-262</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