28 lines
705 B
JavaScript
28 lines
705 B
JavaScript
export function toMoney(num) {
|
|
if (num) {
|
|
if (isNaN(num)) {
|
|
return
|
|
}
|
|
num = typeof num == 'string' ? parseFloat(num) : num //判断是否是字符串如果是字符串转成数字
|
|
num = num.toFixed(2) //保留两位
|
|
num = parseFloat(num) //转成数字
|
|
num = num.toLocaleString() //转成金额显示模式
|
|
//判断是否有小数
|
|
if (num.indexOf('.') == -1) {
|
|
num = num + '.00'
|
|
} else {
|
|
num = num.split('.')[1].length < 2 ? num + '0' : num
|
|
}
|
|
return num //返回的是字符串23,245.12保留2位小数
|
|
} else {
|
|
return (num = '0.00')
|
|
}
|
|
}
|
|
|
|
export function toNum(money) {
|
|
let num = 0
|
|
num = money.split(',').join('')
|
|
return num
|
|
}
|
|
|