number.toExponential
toExponential()
λ©μλλ μ§μ νκΈ°λ²μΌλ‘ Number κ°μ²΄λ₯Ό λνλ΄λ λ¬Έμμ΄μ λ°ννλ€.
function expo(x, f) {
return Number.parseFloat(x).toExponential(f);
}
expo(123456, 2); // "1.23e+5"
expo('123456'); // "1.23456e+5"
expo('oink'); // "NaN"
Syntax
numObj.toExponential([fractionDigits])
Parameters
fractionDigits(Optional)
μμμ λ€μ μλ¦Ώμλ₯Ό μ§μ νλ μ μμ΄λ€. μ«μλ₯Ό μ§μ νλλ° νμν λ§νΌμ μ«μλ‘ κΈ°λ³Έ μ€μ λλ€.
Return value
Number
μμμ μμ ν μ리 μ«μλ‘ μ§μ νκΈ°λ²μΌλ‘ μ£Όμ΄μ§ κ°μ²΄λ₯Ό λνλ΄λ λ¬Έμμ΄μ΄λ©° μμμ μ΄ν fractionDigits
λ€μ μ«μλ‘ λ°μ¬λ¦Όνλ€.
Exceptions
RangeError
fractionDigits
κ° λ무 μκ±°λ λ무 ν¬λ©΄ RangeError
κ° λ°μνλ€.
fractionDigits
κ° 0μμ 20 μ¬μ΄μ κ°μ΄λ©΄ RangeError
μλ¬λ λ°μνμ§ μλλ€. ꡬνμ λ°λΌ λ ν¬κ±°λ μμ κ°λ μ¬μ©ν μ μλ€.
TypeError
Number
κ° μλ κ°μ²΄κ° μ΄ λ©μλλ₯Ό μ€νμν€λ©΄ RangeError
μλ¬κ° λ°μνλ€.
Description
fractionDigits
κ° μλ΅λ κ²½μ°, μμμ μ΄νμ μλ¦Ώμλ κ°μ κ³ μ νκ² λνλ΄λλ° νμν μλ¦Ώμλ‘ κΈ°λ³Έκ°μ΄ μ§μ λλ€.
μ§μλ μμμ μ΄ μλ μ«μ 리ν°λ΄μ toExponential()
λ©μλλ₯Ό μ¬μ©νλ €λ¨Ό, μ μμ 곡백μ λμ΄ μ μ΄ μμμ μΌλ‘ ν΄μλλ κ²μ λ§λλ‘ νλ€. console.log(77 .toExponential());
μ£Όμ΄μ§ κ°μ μλ¦Ώμκ° fractionDigits
λ§€κ°λ³μλ³΄λ€ ν¬λ€λ©΄, μ£Όμ΄μ§ κ°μ fractionDigits
μ κ°κΉμ΄ μλ¦Ώμλ‘ λ°μ¬λ¦Όλμ΄ νλ€. toFixed()
λ©μλμ λ°μ¬λ¦Όμ κ΄ν μ€λͺ
μ μ°Έμ‘°
Examples
toExponential μ¬μ©νκΈ°
const numObj = 77.1234;
// `fractionDigits` κ° μλ΅λ κ²½μ°, μμμ μ΄νμ μλ¦Ώμλ κ°μ κ³ μ νκ² λνλ΄λλ° νμν μλ¦Ώμλ‘ κΈ°λ³Έκ°μ΄ μ§μ λλ€.
numObj.toExponential(); // "7.71234e+1"
numObj.toExponential(4); // "7.7123e+1"
numObj.toExponential(2); // "7.71e+1"
77.1234.toExponential(); // "7.71234e+1"
// μ§μλ μμμ μ΄ μλ μ«μ 리ν°λ΄μ `toExponential()` λ©μλλ₯Ό μ¬μ©νλ €λ¨Ό, μ μμ 곡백μ λμ΄ μ μ΄ μμμ μΌλ‘ ν΄μλλ κ²μ λ§λλ‘ νλ€.
77 .toExponential(); // "7.7e+1"
Last updated
Was this helpful?