RangeError: precision is out of range
ë©ìì§
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)
ìë¬ íì
RangeError
무ìì´ ì못ëììê¹?
ìëì ë©ìëë¤ ì¤ íëìì, ì¤í ì¸ì(argument)ê° ì íëì ë²ì를 ë²ì´ë¬ìµëë¤. :
ì´ ë©ìëë¤ìê² íì©ë ë²ìë 0ë¶í° 20 (ëë 21)ê¹ì§ ì ëë¤. íì§ë§, ECMAScript ì¤íì ìëì ë²ìê¹ì§ íì¥íì¬ íì©íê³ ììµëë¤.
| Method | Firefox (SpiderMonkey) | Chrome, Opera (V8) |
|---|---|---|
Number.prototype.toExponential() |
0 ë¶í° 100 | 0 ë¶í° 20 |
Number.prototype.toFixed() |
-20 ë¶í° 100 | 0 ë¶í° 20 |
Number.prototype.toPrecision() |
1 ë¶í° 100 | 1 ë¶í° 21 |
ì
>ì í¨íì§ ìì ê²½ì°
js
(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
ì í¨í ê²½ì°
js
(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