본문 바로가기

프론트엔드/자바스크립트

js 소수점처리 .tofixed()

let numObj = 1.23456 

console.log(numObj.toFixed()); // 결과: '1'
console.log(numObj.toFixed(6)); // 결과: '1.234560'
console.log(numObj.toFixed(3)); // 결과: '1.235'
console.log(numObj.toFixed(1)); // 결과: '1.2'

출처: https://junghn.tistory.com/entry/JavaScript-소수점-처리-방법-toFixed-사용법과-예제 [코딩 시그널:티스토리]