数字(金钱格式)相互转化
/** * 数字格式化金钱展示 * @param {*} num 串数字 * @returns */ export const numFormat = (num) => { if (typeof (num) != 'number') { num = Number(num) } num = num.toFixed(2); num = parseFloat(num) num = num.toLocaleString(); let floatPart = '.00' // 预定义小数部分 let numArry = num.split('.') // =2表示数据有小数位 if (numArry.length === 2) { floatPart = numArry[1].toString() // 拿到小数部分 if (floatPart.length === 1) { // 补0,实际上用不着 return numArry[0] + '.' + floatPart + '0' } else { return numArry[0] + '.' + floatPart } } else { return num + floatPart } } /** * * 金钱格式化数字 * @param {*} 传字符串或者数字 * @returns */ export const number = (value) => { if (typeof (value) == 'number') { return value } else { if (value.indexOf(',') != -1) { return Number(value) } else { return Number(value.replace(',', '')) } } }
作者:子钦加油
出处:https://www.cnblogs.com/zmdComeOn/
个性签名:努力生活,努力走路
阿里云拼团:https://www.aliyun.com/1111/home?userCode=f4ee1llo1核2G1M,86一年,229三年;2核4G5M,799三年;2核8G5M,1399三年
腾讯云三月采购计划特价:https://cloud.tencent.com/act/cps/redirect?redirect=1073&cps_key=15d0b1673287c43fe946626d9f4e2eee&from=console1核2G1M,88一年;1核2G1M,268三年;2核4G5M,998一年;4核8G5M,2888元三年
出处:https://www.cnblogs.com/zmdComeOn/
个性签名:努力生活,努力走路
阿里云拼团:https://www.aliyun.com/1111/home?userCode=f4ee1llo1核2G1M,86一年,229三年;2核4G5M,799三年;2核8G5M,1399三年
腾讯云三月采购计划特价:https://cloud.tencent.com/act/cps/redirect?redirect=1073&cps_key=15d0b1673287c43fe946626d9f4e2eee&from=console1核2G1M,88一年;1核2G1M,268三年;2核4G5M,998一年;4核8G5M,2888元三年