프론트엔드/Javascript

[메소드]Number.prototype.toFixed()

deep__sea 2023. 7. 26. 08:38
728x90

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
반응형