mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-10 16:48:17 +08:00
38 lines
2.4 KiB
HTML
38 lines
2.4 KiB
HTML
<article id="wikiArticle">
|
||
<div></div>
|
||
<h2 id="消息">消息</h2>
|
||
<pre><code class="language-javascript">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)
|
||
</code></pre>
|
||
<h2 id="错误类型">错误类型</h2>
|
||
<p><a href="Reference/Global_Objects/RangeError" title="RangeError对象标明一个错误,当一个值不在其所允许的范围或者集合中。"><code>RangeError</code></a></p>
|
||
<h2 id="发生了什么错误?">发生了什么错误?</h2>
|
||
<p>在使用<a href="Reference/Global_Objects/Number/toString" title="toString() 方法返回指定 Number 对象的字符串表示形式。"><code>Number.prototype.toString()</code></a>方法时使用了可选的基数参数,参数应该为一个2到36之间的整型(数字),返回对应数字的转换为字符串时表示的该进制对应的数字量。</p>
|
||
<p>为什么小于36呢?因为一个大于(包含等于)10的基数在使用时需要用一个字母表字符来代替。不能超过36是因为拉丁字母表中只有26个字符。</p>
|
||
<p>你可能会用到以下的常见基数:</p>
|
||
<ul>
|
||
<li>2 for <a class="external" href="https://en.wikipedia.org/wiki/Binary_number" rel="noopener">二进制</a>,</li>
|
||
<li>8 for <a class="external" href="https://en.wikipedia.org/wiki/Octal" rel="noopener">八进制</a>,</li>
|
||
<li>10 for <a class="external" href="https://en.wikipedia.org/wiki/Decimal" rel="noopener">十进制</a>,</li>
|
||
<li>16 for <a class="external" href="https://en.wikipedia.org/wiki/Hexadecimal" rel="noopener">十六进制</a>.</li>
|
||
</ul>
|
||
<h2 id="示例">示例</h2>
|
||
<h3 id="错误示例">错误示例</h3>
|
||
<pre><code class="language-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");
|
||
</code></pre>
|
||
<h3 id="正确示例">正确示例</h3>
|
||
<pre><code class="language-js example-good">(42).toString(2); // "101010" (binary)
|
||
(13).toString(8); // "15" (octal)
|
||
(0x42).toString(10); // "66" (decimal)
|
||
(100000).toString(16) // "186a0" (hexadecimal)
|
||
</code></pre>
|
||
<h2 id="参考">参考</h2>
|
||
<ul>
|
||
<li><a href="Reference/Global_Objects/Number/toString" title="toString() 方法返回指定 Number 对象的字符串表示形式。"><code>Number.prototype.toString()</code></a></li>
|
||
</ul>
|
||
</article> |