본문 바로가기

Programing/Javascript, JQuery

[JavaScript] 숫자 세자리마다 콤마 찍기

728x90
반응형

[JavaScript] 숫자 세자리마다 콤마 찍기


function numberWithCommas(x) {

    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    
}

 

출처

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

 

How to print a number with commas as thousands separators in JavaScript

I am trying to print an integer in JavaScript with commas as thousands separators. For example, I want to show the number 1234567 as "1,234,567". How would I go about doing this? Here is how I am...

stackoverflow.com

 

728x90
반응형