目次

数値を3桁でカンマ区切り(number_format)

Intl.NumberFormat を使う方法

<script>
let numberFormat = new Intl.NumberFormat('ja')
let price = 123456789;
console.log(numberFormat.format(price));
</script>

自作関数を使う方法

<script>
let price = 123456789;
console.log(number_format(price));

function number_format(num) {
  return num.toString().replace(/([0-9]+?)(?=(?:[0-9]{3})+$)/g, '$1,');
}
</script>