2、将数字转为货币样式
console.log(number.toLocaleString('zh', { style: 'currency', currency: 'EUR' })); //€123,456.79
console.log(number.toLocaleString('zh', { style: 'currency', currency: 'CNY' })); //¥123,456.79
console.log(number.toLocaleString('zh', { style: 'currency', currency: 'CNY',currencyDisplay:'code' })); //CNY 123,456.79 console.log(number.toLocaleString('zh', { style: 'currency', currency: 'CNY',currencyDisplay:'name' })); //123,456.79人民币
3、将数字转为百分比形式
var num1 = 0.12
var num2 = 2.45
console.log(num1.toLocaleString('zh',{style:'percent'}))
4、将纯数字/字符串数组所有元素用逗号拼接起来
var numArray = [12,564,'55',5,'8'] console.log(numArray.toLocaleString('zh'))
链接:juejin.cn/post/704988…