Front-end π₯π€/JavaScript
[Java Script] μμμ μ리μλ₯Ό μ§μ ν΄μ£Όλ toFixed()λ?
stable_sound
2022. 5. 24. 00:55
toFixed() λ©μλ
- μ«μλ₯Ό κ³ μ μμμ νκΈ°λ²μΌλ‘ νμνλ λ©μλ
- κ³ μ μμμ μΌλ‘ κ°μ νκΈ°ν λμλ λ°μ¬λ¦Όμ νλ€.
ꡬ문
numObj.toFixed([digits])
- digits
: μμμ λ€μ λνλ μ리μ. 0~20 κΉμ§μ κ°μ μ¬μ©ν μ μλ€. κ°μ μ§μ νμ§ μμΌλ©΄ 0μ΄ μ¬μ©λλ€.
μμ
let num = 1234.56789;
console.log(num.toFixed()); // 1235
console.log(num.toFixed(1)); // 1234.6
console.log(num.toFixed(2)); // 1234.57
console.log(num.toFixed(7)); // 1234.5678900 : λΉ κ³΅κ°μ 0μΌλ‘ μ±μ΄λ€.
console.log((2.34).toFixed(1)); // 2.3 : 4λ λ°μ¬λ¦Όμλκ³ λ²λ €μ§λ€.
console.log((2.35).toFixed(1)); // 2.4 : 5λ λ°μ¬λ¦Όλλ€.
λ°±μ€μμ μ²μ μ¬μ©ν΄λ³Έ λ¬Έμ
λ°±μ€ 4344λ² : νκ· μ λκ² μ§
[node.js] λ°±μ€ 4344λ² : νκ· μ λκ² μ§
λ¬Έμ λνμ μλ΄κΈ°λ€μ 90%λ μμ μ΄ λ°μμ νκ· μ λλλ€κ³ μκ°νλ€. λΉμ μ κ·Έλ€μκ² μ¬ν μ§μ€μ μλ €μ€μΌ νλ€. μ μΆλ ₯ μμ€μ½λ const input = require('fs').readFileSync('dev/stdin').toString()...
jeongeum1202.tistory.com
μ°Έκ³
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed
Number.prototype.toFixed() - JavaScript | MDN
toFixed() λ©μλλ μ«μλ₯Ό κ³ μ μμμ νκΈ°λ²(fixed-point notation)μΌλ‘ νμν©λλ€.
developer.mozilla.org