数値をカンマ区切りにする
正規表現を使う方法
code:js
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
numberWithCommas(10000)
Number.prototype.toLocaleString() を使う方法
code:js
(10000).toLocaleString()
参考
formatting - How to print a number with commas as thousands separators in JavaScript - Stack Overflow
Number.prototype.toLocaleString() - JavaScript | MDN
Javascriptで数字のカンマ区切り表示メモ - Qiita
#JavaScript