【修改】 增加注释
This commit is contained in:
@@ -3,11 +3,13 @@ export function formatMoney(money) {
|
|||||||
re = /\d{3}$/,
|
re = /\d{3}$/,
|
||||||
result = ''
|
result = ''
|
||||||
var point = ''
|
var point = ''
|
||||||
|
// 存在小数点 分开整数和小数点
|
||||||
if (num.indexOf('.') !== -1) {
|
if (num.indexOf('.') !== -1) {
|
||||||
point = num.substring(num.indexOf('.'))
|
point = num.substring(num.indexOf('.'))
|
||||||
num = parseInt(num)
|
num = parseInt(num)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 循环添加逗号
|
||||||
while (re.test(num)) {
|
while (re.test(num)) {
|
||||||
result = RegExp.lastMatch + result
|
result = RegExp.lastMatch + result
|
||||||
if (num !== RegExp.lastMatch) {
|
if (num !== RegExp.lastMatch) {
|
||||||
@@ -18,19 +20,25 @@ export function formatMoney(money) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (num) {
|
if (num) {
|
||||||
result = num + result
|
result = num + result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 去掉负数符号后面的逗号
|
||||||
function _(result) {
|
function _(result) {
|
||||||
return result.replace('-,', '-')
|
return result.replace('-,', '-')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果第一位是逗号 去掉逗号
|
||||||
function __(result) {
|
function __(result) {
|
||||||
if (result[0] === ',') {
|
if (result[0] === ',') {
|
||||||
result = result.substring(1)
|
result = result.substring(1)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 第一位是 小数点开头的 前面加上 0
|
||||||
function ___(result) {
|
function ___(result) {
|
||||||
if (result[0] === '.') {
|
if (result[0] === '.') {
|
||||||
result = '0' + result
|
result = '0' + result
|
||||||
|
|||||||
Reference in New Issue
Block a user