// 金额格式化,20000->20.000
moneyFormat(num) {
const RegExp = /B(?=(?:d{3})+(?!d))/g
if (num === undefined || num === null) return
num = num.toString()
if (num.indexOf('.') >= 0) {
var lastIndex = num.lastIndexOf('.')
var betweenDot = num.substring(lastIndex + 1, num.length)
if (betweenDot && parseInt(betweenDot)) {
const beforeDot = num.substring(0, lastIndex)
const bereeDotFormat = beforeDot && beforeDot.toString().replace(RegExp, '.')
num =
bereeDotFormat +
',' +
num.substring(lastIndex + 1, num.length)
return num
} else {
const tempNum = num.substring(0, lastIndex)
num = tempNum && tempNum.toString().replace(RegExp, '.')
return num
}
}
let numformat = num && num.toString().replace(RegExp, '.')
return numformat
},
最后
以上就是稳重小刺猬最近收集整理的关于金额格式化的全部内容,更多相关金额格式化内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复