Number.prototype.toExponential()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since 2015ë 7ì.
toExponential() ë©ìëë ì«ì를 ì§ì í기ë²ì¼ë¡ íê¸°í´ ë°íí©ëë¤.
ìëí´ ë³´ê¸°
function expo(x, f) {
return Number.parseFloat(x).toExponential(f);
}
console.log(expo(123456, 2));
// Expected output: "1.23e+5"
console.log(expo("123456"));
// Expected output: "1.23456e+5"
console.log(expo("oink"));
// Expected output: "NaN"
구문
numObj.toExponential([fractionDigits]);
매ê°ë³ì
fractionDigitsOptional-
ììì ì´íë¡ ííí ì릿ìì ëë¤. 기본ê°ì 주ì´ì§ ê°ì ëíë´ëë° íìí ì릿ìì ëë¤.
ë°í ê°
주ì´ì§ Number ê°ì ì«ì íì리ì ììì , ììì ì´í fractionDigits ì릿ìë§í¼ ë°ì¬ë¦¼íì¬ ì§ì í기ë²ì¼ë¡ ëíë¸ ë¬¸ìì´ì ë°íí©ëë¤.
ìì¸
RangeError-
fractionDigitsê° ë무 ìê±°ë ë무 í¬ë©´RangeErrorìë¬ê° ë°ìí©ëë¤.fractionDigitsê° 0ìì 20 ì¬ì´ì ê°ì´ë©´RangeErrorìë¬ë ë°ìíì§ ììµëë¤. 구íì ë°ë¼ ë í¬ê±°ë ìì ê°ë ì¬ì© í ì ììµëë¤. TypeError-
Numberê° ìë ê°ì²´ê° ì´ ë©ìë를 ì¤íìí¤ë©´RangeErrorìë¬ê° ë°ìí©ëë¤.
ì¤ëª
fractionDigits 매ê°ë³ì를 ìëµíë©´, 기본ì ì¼ë¡ 주ì´ì§ ê°ì í¹ì í기 ìí´ íìí ì릿ìë§í¼ì´ ììì ì´í ì릿ìê° ë©ëë¤.
ì§ìë ììì ì´ ìë ì«ì 리í°ë´ì toExponential() ë©ìë를 ì¬ì©íë ¤ë©´, ì ìì 공백ì ëì´ ì ì´ ììì ì¼ë¡ í´ìëë ê²ì ë§ëë¡ í©ëë¤.
주ì´ì§ ê°ì ì릿ìê° fractionDigits 매ê°ë³ìë³´ë¤ í¬ë¤ë©´, 주ì´ì§ ê°ì fractionDigitsì ê°ê¹ì´ ì릿ìë¡ ë°ì¬ë¦¼ëì´ ííë©ëë¤. toFixed() ë©ìëì ë°ì¬ë¦¼ì ê´í ì¤ëª
ì´ toExponential() ë©ìëìë ë§ì°¬ê°ì§ë¡ ì ì©ë©ëë¤.
ìì
>toExponential ì¬ì©í기
var numObj = 77.1234;
console.log(numObj.toExponential()); // logs 7.71234e+1
console.log(numObj.toExponential(4)); // logs 7.7123e+1
console.log(numObj.toExponential(2)); // logs 7.71e+1
console.log((77.1234).toExponential()); // logs 7.71234e+1
console.log((77).toExponential()); // logs 7.7e+1
ëª ì¸
| Specification |
|---|
| ECMAScript® 2027 Language Specification> # sec-number.prototype.toexponential> |