【修改】统计金额修改为千分位展示

This commit is contained in:
fengachen
2022-06-02 11:38:14 +08:00
parent f55b77e7a0
commit a9ddce0a21
8 changed files with 200 additions and 29 deletions
+41
View File
@@ -0,0 +1,41 @@
export function formatMoney(money) {
var num = (money || 0).toString(),
re = /\d{3}$/,
result = ''
var point = ''
if (num.indexOf('.') !== -1) {
point = num.substring(num.indexOf('.'))
num = parseInt(num)
}
while (re.test(num)) {
result = RegExp.lastMatch + result
if (num !== RegExp.lastMatch) {
result = ',' + result
num = RegExp.leftContext
} else {
num = ''
break
}
}
if (num) {
result = num + result
}
function _(result) {
return result.replace('-,', '-')
}
function __(result) {
if (result[0] === ',') {
result = result.substring(1)
}
return result
}
function ___(result) {
if (result[0] === '.') {
result = '0' + result
}
return result
}
return ___(__(_(result) + point))
}