toLocaleString(locale, options)
- local String,用于指定本地环境中存在的语言系统
- options Objec,附加选项,用来指定字符串的显示格式
// 数字分割 123,456.123const numOne = 123456.123;numOne.toLocaleString()// 数字转为百分比 12%const numTwo = 0.12;numTwo.toLocaleString('zh', { style: 'percent' ));// 数字转为货币表示法 ¥1,000,000.00const numThree = 1000000;numThree.toLocaleString('zh', { style: 'currency', currency: 'cny' });// CNY 1,000,000.00numThree.toLocaleString('zh', { style: 'currency', currency: 'cny', currencyDisplay: 'code' });// 1,000,000.00人民币numThree.toLocaleString('zh', { style: 'currency', currency: 'cny', currencyDisplay: 'name' });
