数值千分位格式化方法
主要是通过Number.protoType.toLocaleString方法实现,通过传入数值单位去进行判断,具体方法还要根据自己的业务去处理
/**
* 根据货币类型转换成对应货币格式的值
* @param value
* @param format
*/
export function convertCurrencyFormat(value, format) {
if(isValueNull(value)){
return value
}
let option = {}
let formatType = ''
switch (format) {
//人民币
case "¥": {
formatType = 'ch-CN'
option = {style:"currency", currency:"CNY"}
break
}
//美元
case "$": {
formatType = 'en-US'
option = {style:"currency", currency:"USD"}
break
}
default:
formatType = 'ch-CN'
option = {style:"currency", currency:"CNY"}
break
}
return value.toLocaleString(formatType, option)
}
参考链接:菜鸟教程toLocaleString