Intl.NumberFormat - developer.mozilla.org
JavaScriptで数値フォーマットする標準API「Intl.NumberFormat」 (カンマ区切り、円・ドル表記、漢数字など)
// 3 桁カンマ区切り
const formatter = new Intl.NumberFormat('ja-JP')
formatter.format(1000) // '1,000'
// ついでに浮動小数の精度まるめ (四捨五入)
// maximumFractionDigits option で少数点の最大桁数を指定可能
//
formatter.format(123.5554) // '123.555'
formatter.format(123.5555) // '123.556'
// 金額フォーマット
const formatter = new Intl.NumberFormat('ja-JP', {
style: 'currency',
currency: 'JPY',
})
formatter.format(1000) // '¥1,000'
// 漢数字 (中国で利用される簡体字の漢数字 10 進数)
const formatter = new Intl.NumberFormat('zh-Hans-CN-u-nu-hanidec')
formatter.format(1234567890) // '一,二三四,五六七,八九〇'