【修改】 增加注释

This commit is contained in:
fengachen
2022-06-02 13:44:30 +08:00
parent a9ddce0a21
commit 0cc0e754e4
+9 -1
View File
@@ -3,11 +3,13 @@ export function formatMoney(money) {
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) {
@@ -18,19 +20,25 @@ export function formatMoney(money) {
break
}
}
if (num) {
result = num + result
}
// 去掉负数符号后面的逗号
function _(result) {
return result.replace('-,', '-')
}
// 如果第一位是逗号 去掉逗号
function __(result) {
if (result[0] === ',') {
result = result.substring(1)
}
return result
}
// 第一位是 小数点开头的 前面加上 0
function ___(result) {
if (result[0] === '.') {
result = '0' + result