aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/errors/precision_range/index.html
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/javascript/reference/errors/precision_range/index.html
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/javascript/reference/errors/precision_range/index.html')
-rw-r--r--files/zh-cn/web/javascript/reference/errors/precision_range/index.html96
1 files changed, 96 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/errors/precision_range/index.html b/files/zh-cn/web/javascript/reference/errors/precision_range/index.html
new file mode 100644
index 0000000000..42e2c703a9
--- /dev/null
+++ b/files/zh-cn/web/javascript/reference/errors/precision_range/index.html
@@ -0,0 +1,96 @@
+---
+title: 'RangeError: precision is out of range'
+slug: Web/JavaScript/Reference/Errors/Precision_range
+tags:
+ - JavaScript
+ - 范围错误
+ - 错误
+translation_of: Web/JavaScript/Reference/Errors/Precision_range
+---
+<div>{{jsSidebar("Errors")}}</div>
+
+<h2 id="描述">描述</h2>
+
+<pre class="syntaxbox">RangeError: precision {0} out of range (Firefox)
+RangeError: toExponential() argument must be between 0 and 20 (Chrome)
+RangeError: toFixed() digits argument must be between 0 and 20 (Chrome)
+RangeError: toPrecision() argument must be between 1 and 21 (Chrome)
+</pre>
+
+<h2 id="错误类型">错误类型</h2>
+
+<p>{{jsxref("RangeError")}}</p>
+
+<h2 id="什么地方出错了?">什么地方出错了?</h2>
+
+<p>以下的某个方法传入了一个超出精度范围的参数:</p>
+
+<ul>
+ <li>{{jsxref("Number.prototype.toExponential()")}}</li>
+ <li>{{jsxref("Number.prototype.toFixed()")}}</li>
+ <li>{{jsxref("Number.prototype.toPrecision()")}}</li>
+</ul>
+
+<p>通常这些方法允许的参数范围介于0和20(或21)之间。需要注意的是,ECMAScript标准是允许扩展这个范围的。</p>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Method</th>
+ <th scope="col">Firefox (SpiderMonkey)</th>
+ <th scope="col">Chrome, Opera (V8)</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{jsxref("Number.prototype.toExponential()")}}</td>
+ <td>0 to 100</td>
+ <td>0 to 20</td>
+ </tr>
+ <tr>
+ <td>{{jsxref("Number.prototype.toFixed()")}}</td>
+ <td>-20 to 100</td>
+ <td>0 to 20</td>
+ </tr>
+ <tr>
+ <td>{{jsxref("Number.prototype.toPrecision()")}}</td>
+ <td>1 to 100</td>
+ <td>1 to 21</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="示例">示例</h2>
+
+<h3 id="错误的示例">错误的示例</h3>
+
+<pre class="brush: js example-bad">77.1234.toExponential(-1); // RangeError
+77.1234.toExponential(101); // RangeError
+
+2.34.toFixed(-100); // RangeError
+2.34.toFixed(1001); // RangeError
+
+1234.5.toPrecision(-1); // RangeError
+1234.5.toPrecision(101); // RangeError
+</pre>
+
+<h3 id="正确的示例">正确的示例</h3>
+
+<pre class="brush: js example-good">77.1234.toExponential(4); // 7.7123e+1
+77.1234.toExponential(2); // 7.71e+1
+
+2.34.toFixed(1); // 2.3
+2.35.toFixed(1); // 2.4 (note that it rounds up in this case)
+
+5.123456.toPrecision(5); // 5.1235
+5.123456.toPrecision(2); // 5.1
+5.123456.toPrecision(1); // 5
+</pre>
+
+<h2 id="相关页面">相关页面</h2>
+
+<ul>
+ <li>{{jsxref("Number.prototype.toExponential()")}}</li>
+ <li>{{jsxref("Number.prototype.toFixed()")}}</li>
+ <li>{{jsxref("Number.prototype.toPrecision()")}}</li>
+</ul>