【修改】统计金额修改为千分位展示
This commit is contained in:
@@ -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))
|
||||
}
|
||||
Reference in New Issue
Block a user