在官方代码后补充 sums[index] = parseFloat(sums[index]).toFixed(2);
getSummaries(param) {
const { columns, data } = param;
const sums = [];
const nu = '';
columns.forEach((column, index) => {
if (index === 0) {
sums[index] = '合计';
return;
}
if( index === 1 || index === 2 ){
sums[index] = 'N/A';
return;
}
const values = data.map(item => Number(item[column.property]));
if (!values.every(value => isNaN(value))) {
sums[index] = values.reduce((prev, curr) => {
const value = Number(curr);
if (!isNaN(value)) {
return prev + curr;
} else {
return prev;
}
}, 0);
//处理精度代码
if( index === 6 || index === 8 || index === 14 || index === 13 || index === 15 || index === 16){
sums[index] = parseFloat(sums[index]).toFixed(2);
}
// sums[index] += ' 元';
} else {
sums[index] = 'N/A';
}
});
return sums;
},