본문 바로가기

■ Web개발/Javascript

math.round를 통해 소수점 표현하기

Math.round(numbers.value * 10) / 10;

Math.round(numbers.value * 10) / 10; // 소수점 한자리
Math.round(numbers.value * 100) / 100; // 소수점 두자리
Math.round(numbers.value * 1000) / 1000; // 세자리

 

표현하고싶은 자릿수에 따라

* 100, 1000 등으로 변경하면 된다.