-
[메소드]Number.prototype.toFixed()프론트엔드/Javascript 2023. 7. 26. 08:38
toFixed() 메서드는 숫자를 고정 소수점 표기법(fixed-point notation)으로 표시합니다.
function financial(x) { return Number.parseFloat(x).toFixed(2); } console.log(financial(123.456)); // Expected output: "123.46" console.log(financial(0.004)); // Expected output: "0.00" console.log(financial('1.23e+5')); // Expected output: "123000.00" > "123.46" > "0.00" > "123000.00"
728x90반응형'프론트엔드 > Javascript' 카테고리의 다른 글
[JS] 배열 분할 할당(Destructuring Assignment) (0) 2023.07.27 [메소드] Array(n).fill(x) (0) 2023.07.06 [Javascript] 문자열 '... ' 생략 처리하기 (0) 2022.02.04