π Reference
πΒ Chapter
toFixed() λ©μλλ μ«μλ₯Ό κ³ μ μμμ νκΈ°λ²μΌλ‘ νκΈ°ν΄ λ°ννλ€.toFixed() λ©μλλ μ«μλ₯Ό κ³ μ μμμ νκΈ°λ²μΌλ‘ νκΈ°ν΄ λ°ννλ€.toFixed() ν¨μλ,Β λΆλμμμ (Floating Point) μ«μλ₯Ό κ³ μ μμμ (Fixed Point) μ«μλ‘ λ°κΎΈμ΄μ 리ν΄νλ€.numObj.toFixed([digits])
digits
μμ 1
var numObj = 12345.6789;
numObj.toFixed(); // Returns '12346': λ°μ¬λ¦Όνλ©°, μμ λΆλΆμ λ¨κΈ°μ§ μμ΅λλ€.
numObj.toFixed(1); // Returns '12345.7': λ°μ¬λ¦Όν©λλ€.
numObj.toFixed(6); // Returns '12345.678900': λΉ κ³΅κ°μ 0μΌλ‘ μ±μλλ€.
(1.23e+20).toFixed(2); // Returns '123000000000000000000.00'
(1.23e-10).toFixed(2); // Returns '0.00'
2.34.toFixed(1); // Returns '2.3'
2.35.toFixed(1); // Returns '2.4'. μ΄ κ²½μ°μλ μ¬λ¦Όμ ν©λλ€.
-2.34.toFixed(1); // Returns -2.3 (μ°μ°μμ μ μ©μ΄ μ°μ μ΄κΈ° λλ¬Έμ, μμμ κ²½μ° λ¬Έμμ΄λ‘ λ°ννμ§ μμ΅λλ€...)
(-2.34).toFixed(1); // Returns '-2.3' (...κ΄νΈλ₯Ό μ¬μ©ν κ²½μ° λ¬Έμμ΄μ λ°νν©λλ€.)