diff --git a/src/views/dashboard/index.vue b/src/views/dashboard/index.vue index b3de211..a43d691 100644 --- a/src/views/dashboard/index.vue +++ b/src/views/dashboard/index.vue @@ -518,45 +518,36 @@ export default { .catch((error) => {}); }, methods: { - formatResult(num) { + formatResult(originalNum) { // 1. 先处理浮点数精度问题(乘以100后四舍五入到整数,再除以100保留两位小数) - if(!num){ - return '0' + if(!originalNum){ + return 0 } - const processed = Math.round(num * 100) / 100; + const multiplied = Math.round(originalNum * 100); // 0.28 * 100 = 28 → 处理后为28 - // 2. 判断是否为整数(小数部分为0) - if (processed % 1 === 0) { - // 是整数,直接返回整数形式(不带小数位) - return processed.toString(); - } else { - // 不是整数,保留两位小数 - return processed.toFixed(2); - } + // 2. 判断是否为整数(乘以100后是否无小数) + if (multiplied % 1 === 0) { + // 是整数,直接显示整数(如28) + return multiplied; + } else { + // 不是整数,保留两位小数(如56.50) + return (multiplied / 100).toFixed(2); + } }, async getCarry () { const res = await carry(this.carrySelect); //组织数据 let setData = function(data, constData, showData) { - data.filter(function(item) { - if (item) { - constData.push(1); - showData.push(item); - } else { - constData.push(0); - showData.push({ - value: 1, - itemStyle: { - normal: { - borderColor: "rgba(0,0,0,0)", - borderWidth: 2, - color: "rgba(0,0,0,0)", - }, - }, - }); - } - }); + data.forEach(function(item) { + if (item && Number(item.value) !== 0) { + constData.push(1); + showData.push(item); + } else { + constData.push(1); // 让底部 diamond 始终有 + showData.push(null); // 顶部 diamond 不显示 + } + }); } //组织颜色 let setColor = function(colorArr) {