diff --git a/src/views/dashboard/index.vue b/src/views/dashboard/index.vue index 9208d77..b3de211 100644 --- a/src/views/dashboard/index.vue +++ b/src/views/dashboard/index.vue @@ -518,6 +518,22 @@ export default { .catch((error) => {}); }, methods: { + formatResult(num) { + // 1. 先处理浮点数精度问题(乘以100后四舍五入到整数,再除以100保留两位小数) + if(!num){ + return '0' + } + const processed = Math.round(num * 100) / 100; + + // 2. 判断是否为整数(小数部分为0) + if (processed % 1 === 0) { + // 是整数,直接返回整数形式(不带小数位) + return processed.toString(); + } else { + // 不是整数,保留两位小数 + return processed.toFixed(2); + } + }, async getCarry () { const res = await carry(this.carrySelect); @@ -592,11 +608,11 @@ export default { // 0; // }); let curPlan = res?.map(i => { - const { use_money_total,paid_plan_total,money_total_2,money_total_1 } = i + const { use_money_total,paid_plan_total,money_total_2,money_total_1,plan_rate } = i let curPlan_total = Math.round(Number(paid_plan_total||0)) + Math.round(Number(use_money_total||0)) return { - value:plan_rate*100, + value:this.formatResult(plan_rate), // value:Number(money_total_2) ? ((( curPlan_total / Number(money_total_2 ||0)) * 10000) / 100).toFixed(2) : // ((( curPlan_total / Number(money_total_1 ||0)) * 10000) / 100).toFixed(2), money:parseFloat(curPlan_total).toFixed(2) @@ -604,9 +620,9 @@ export default { }); let curAct = res?.map(i => { - const { use_money_total,money_total_2,money_total_1 } = i + const { use_money_total,money_total_2,money_total_1,act_rate } = i return { - value:act_rate*100, + value:this.formatResult(act_rate), // value:Number(money_total_2) ? // (Math.round((Number(use_money_total||0) / Number(money_total_2||0)) * 10000) / 100).toFixed(2) : // (Math.round((Number(use_money_total||0) / Number(money_total_1||0)) * 10000) / 100).toFixed(2), @@ -615,13 +631,15 @@ export default { }); let nextPlan = res?.map(i => { - const { use_money_total,use_money_total_next,paid_plan_total_next,money_total_2,money_total_1 } = i + + const { plan_rate_next,use_money_total,use_money_total_next,paid_plan_total_next,money_total_2,money_total_1 } = i // if(Number(paid_plan_total_next)===0){ // return 0 // } let nextPlan_total = Math.round(Number(paid_plan_total_next||0)) + Math.round(Number(use_money_total||0)) return { - vaule:plan_rate_next*100, + + value:this.formatResult(plan_rate_next), // value:Number(money_total_2) ? (((nextPlan_total / Number(money_total_2||0)) * 10000) / 100).toFixed(2) : // (((nextPlan_total / Number(money_total_1||0)) * 10000) / 100).toFixed(2), money:parseFloat(nextPlan_total).toFixed(2)