首页数据

master
lion 1 year ago
parent 3a60f329b7
commit ecdceeaa61

@ -518,20 +518,20 @@ 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();
// 2. 判断是否为整数(乘以100后是否无小数)
if (multiplied % 1 === 0) {
// 是整数,直接显示整数(如28)
return multiplied;
} else {
// 不是整数,保留两位小数
return processed.toFixed(2);
// 不是整数,保留两位小数(如56.50)
return (multiplied / 100).toFixed(2);
}
},
async getCarry () {
@ -539,22 +539,13 @@ export default {
//组织数据
let setData = function(data, constData, showData) {
data.filter(function(item) {
if (item) {
data.forEach(function(item) {
if (item && Number(item.value) !== 0) {
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)",
},
},
});
constData.push(1); // 让底部 diamond 始终有
showData.push(null); // 顶部 diamond 不显示
}
});
}

Loading…
Cancel
Save