Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1028110 of RangeError: radix must be an integer

  • Revision slug: Web/JavaScript/Reference/Errors/Bad_radix
  • Revision title: RangeError: radix must be an integer at least 2 and no greater than 36
  • Revision id: 1028110
  • Created:
  • Creator: fscholz
  • Is current revision? No
  • Comment

Revision Content

{{jsSidebar("Errors")}}

Message

RangeError: radix must be an integer at least 2 and no greater than 36 (Firefox)
RangeError: toString() radix argument must be between 2 and 36 (Chrome)

Error type

{{jsxref("RangeError")}}

What went wrong?

You were using the optional radix parameter with the {{jsxref("Number.prototype.toString()")}} method. This parameter must be an integer (a number) between 2 and 36 specifying the base of the number system you want to use for representing numeric values.

Why is it limited to 36? A radix that is larger than 10 uses alphabetical characters as digits. Therefore, the radix can not be larger than 36 as the Latin alphabet has 26 characters only.

You probably want to use one of the common radices:

Examples

Invalid cases

(42).toString(0);
(42).toString(1);
(42).toString(37);
(42).toString(150);
// You cannot use a string like this for formatting:
(12071989).toString("MM-dd-yyyy");

Valid cases

(42).toString(2);     // "101010" (binary)
(13).toString(8);     // "15"     (octal)
(0x42).toString(10);  // "66"     (decimal)
(100000).toString(16) // "186a0"  (hexadecimal)

See also

  • {{jsxref("Number.prototype.toString()")}}

Revision Source

<div>{{jsSidebar("Errors")}}</div>

<h2 id="Message">Message</h2>

<pre class="syntaxbox">
RangeError: radix must be an integer at least 2 and no greater than 36 (Firefox)
RangeError: toString() radix argument must be between 2 and 36 (Chrome)
</pre>

<h2 id="Error_type">Error type</h2>

<p>{{jsxref("RangeError")}}</p>

<h2 id="What_went_wrong?">What went wrong?</h2>

<p>You were using the optional <code>radix</code> parameter with the {{jsxref("Number.prototype.toString()")}} method. This parameter must be an integer (a number) between 2 and 36 specifying the base of the number system you want to use for representing numeric values.</p>

<p>Why is it limited to 36? A radix that is larger than 10 uses alphabetical characters as digits. Therefore, the radix can not be larger than 36 as the Latin alphabet has 26 characters only.</p>

<p>You probably want to use one of the common radices:</p>

<ul>
 <li>2 for <a href="https://en.wikipedia.org/wiki/Binary_number">binary numbers</a>,</li>
 <li>8 for <a href="https://en.wikipedia.org/wiki/Octal">octal numbers</a>,</li>
 <li>10 for <a href="https://en.wikipedia.org/wiki/Decimal">decimal numbers</a>,</li>
 <li>16 for <a href="https://en.wikipedia.org/wiki/Hexadecimal">hexadecimal numbers</a>.</li>
</ul>

<h2 id="Examples">Examples</h2>

<h3 id="Invalid_cases">Invalid cases</h3>

<pre class="brush: js example-bad">
(42).toString(0);
(42).toString(1);
(42).toString(37);
(42).toString(150);
// You cannot use a string like this for formatting:
(12071989).toString("MM-dd-yyyy");
</pre>

<h3 id="Valid_cases">Valid cases</h3>

<pre class="brush: js example-good">
(42).toString(2);     // "101010" (binary)
(13).toString(8);     // "15"     (octal)
(0x42).toString(10);  // "66"     (decimal)
(100000).toString(16) // "186a0"  (hexadecimal)
</pre>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{jsxref("Number.prototype.toString()")}}</li>
</ul>
Revert to this revision