본문 바로가기
자바스크립트

자바스크립트 숫자 3자리 마다 콤마 찍기

by 개발하는 늑대 2020. 8. 17.
728x90

숫자 를 다루다 보면 3자리수로 컴마를 찍어 줘야 할때가 있다.

 

  • 아래 소스를 참고 하면 된다.
  • function numberWithCommas(x) {
        return x.toString().replace(/\B(?<!\.\d*)(?=(\d{3})+(?!\d))/g, ",");
    }

    출처: https://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript

    728x90