프로그래밍/JS,TS

[JS] 소수점 출력

dev_NineFive 2023. 4. 24. 23:54

js에서 number를 출력하면 기본적으로 소수점이 0일때는 버리고 출력됩니다

소수점을 출력할 땐 toFixed로 소수점 자릿수를 지정해주면 됩니다

ex)

const n = 4.0;
console.log(n); //4 

console.log(n.toFixed(1)); // 4.0