金额转换
amountChange(val) {
return parseFloat(val).toFixed(2).replace(/\B(?=(\d{3})+\b)/g,',') // 零宽断言
},
amountChange(8600) // 8,600.00
amountChange(18600) // 18,600.00
amountChange(1118600) // 1,118,600.00
amountChange(val) {
var num = val.toFixed(2);
num = parseFloat(num)
num = num.toLocaleString();
return num
},
amountChange(8600) // 8,600
amountChange(18600) // 18,600
amountChange(1118600) // 1,118,600
Number.prototype.toLocaleString
toLocaleString(“en-US”,{style:“currency”,currency:“USD”})
toLocaleString(“zh-Hans-CN”,{style:“currency”,currency:“CNY”})
toLocaleString(‘ja-JP’, { style: ‘currency’, currency: ‘JPY’ })
toLocaleString(‘de-DE’, { style: ‘currency’, currency: ‘EUR’ })
…
- style:可选值为 decimal(小数)、currency(货币)或 percent(百分比);
- currency:设置为货币样式时使用的符号,支持列表在这里;
- 等等
padStart