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-사용법과-예제 [코딩 시그널:티스토리]
'프론트엔드 > 자바스크립트' 카테고리의 다른 글
자바스크립트: 시간을 초단위로 바꾸는 법 (0) | 2023.04.25 |
---|---|
[JSZip 라이브러리] 이미지 파일을 압축된 폴더로 다운로드 (0) | 2023.03.20 |
프로토타입체인 (0) | 2022.07.25 |
클래스와 인스턴스 (0) | 2022.07.22 |
객체지향 프로그래밍 (0) | 2022.07.22 |