cyywl_server/yudao-ui-app/utils/money.js

28 lines
705 B
JavaScript
Raw Permalink Normal View History

2023-05-31 11:06:26 +08:00
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
}