1、在数字类型上的应用
1、整数部分可以直接转化为每三位加一个逗号
const num = 1234555;
num.toLocalString(); // 1,234,555
2、带有options参数情况–style
style 属性 – 表示格式化时使用的样式(默认值是 decimal 也就是纯数字,也可以是 percent 百分比以及 currency 货币),举个栗子
const num = 2333333;
num.toLocaleString('zh',{
style:'decimal'}); //2,333,333
num.toLocaleString('zh',{
style:'percent'}); // 233,333,300%
num.toLocaleString('zh',{
style:'currency'}); // 报错
需要特别注意的是:style为currency时,必须同时指定currency(currencyDisplay有无皆可)才行。
以下举例:
const num = 2333333
num.toLocaleString('zh',{
style:'currency' , currency:'CNY' }); //¥2,333,333.00
number.toLocaleString('ja-JP', {
style