Baseline Widely available
toPrecision()
ë©ìëë Number
ê°ì²´ë¥¼ ì§ì ë ì ë°ëë¡ ëíë´ë 문ìì´ì ë°ííë¤.
function precise(x) {
return x.toPrecision(4);
}
console.log(precise(123.456));
// Expected output: "123.5"
console.log(precise(0.004));
// Expected output: "0.004000"
console.log(precise(1.23e5));
// Expected output: "1.230e+5"
문ë²
numObj.toPrecision([precision]);
íë¼ë¯¸í°
precision
ì íì íë¼ë¯¸í°. ì í¨ ì릿ì를 ì§ì íë ì ì.
ê³ ì ììì ëë ì§ì í기ë²ì Number
ê°ì²´ë¥¼ ì ë° ì í¨ ì«ìë¡ ë°ì¬ë¦¼ í 문ìì´ì
ëë¤. toPrecision()
ìë ì ì©ëë Number.prototype.toFixed()
ë©ìëì ëí ì¤ëª
ìì ë°ì¬ë¦¼ì ëí ì¤ëª
ì 참조íì¸ì.
precision(ì ë°ë)
ì¸ìê° ìëµëë©´ Number.prototype.toString()
ì²ë¼ ìëí©ëë¤. precision(ì ë°ë)
ì¸ìê° ì ìê° ìë ê°ì´ë©´ ê°ì¥ ê°ê¹ì´ ì ìë¡ ë°ì¬ë¦¼ë©ëë¤.
RangeError
precision(ì ë°ë)
ê° 1ìì 100 ì¬ì´ê° ìë ê²½ì° RangeError
ê° ë°ìí©ëë¤. 구íì ë í° ê°ê³¼ ë ìì ê°ì ì§ìí ì ììµëë¤. ECMA-262ë ìµë 21 ì리ì ì ë°ë ë§ì ì구í©ëë¤.
toPrecision
ì¬ì©
var numObj = 5.123456;
console.log(numObj.toPrecision()); // logs '5.123456'
console.log(numObj.toPrecision(5)); // logs '5.1235'
console.log(numObj.toPrecision(2)); // logs '5.1'
console.log(numObj.toPrecision(1)); // logs '5'
numObj = 0.000123;
console.log(numObj.toPrecision()); // logs '0.000123'
console.log(numObj.toPrecision(5)); // logs '0.00012300'
console.log(numObj.toPrecision(2)); // logs '0.00012'
console.log(numObj.toPrecision(1)); // logs '0.0001'
// ì¼ë¶ ìí©ììë ì§ì í기ë²ì´ ë°í ë ì ììµëë¤
console.log((1234.5).toPrecision(2)); // logs '1.2e+3'
ëª
ì¸ ë¸ë¼ì°ì í¸íì± See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4