250x250
Notice
Recent Posts
Recent Comments
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

진스

숫자 사이 콤마(,) 넣는 방법 javascript 본문

JavaScript

숫자 사이 콤마(,) 넣는 방법 javascript

입방정 2022. 6. 20. 10:52
728x90

정규표현식

let price = 1000000;
let result = price.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
console.log(result); //1,000,000

toLocaleString()

const price = 1000000;

let result = price.toLocaleString(); //인자를 넣지않으면 default locale이 됨
console.log(result); //1,000,000

let result = price.toLocaleString('ko-KR');
console.log(result); //1,000,000
728x90
Comments