4.20 修复详审设置累加浮点数精度问题

This commit is contained in:
jl-zhoujl2
2023-04-20 13:50:38 +08:00
parent eae7846d98
commit 4d530af875

View File

@ -17,7 +17,9 @@ export const checkUnEmp = (val: any) => {
//计算一个table的最高分 //计算一个table的最高分
export const subCountScore = (subData: any) => { export const subCountScore = (subData: any) => {
return subData?.detailList?.reduce((preValue: any, item: any) => { return preValue + parseFloat(item.highScore) }, 0) const mul = 10 ^ 5;
const sum = subData?.detailList?.reduce((preValue: any, item: any) => { return preValue + item.highScore * mul }, 0);
return Math.round(sum) / mul;
} }
//单选取最大 //单选取最大
@ -33,16 +35,17 @@ export function chooseOne(data: any) {
//多选加和 //多选加和
export function chooseMany(data: any) { export function chooseMany(data: any) {
let max = 0; let max = 0;
const mul = 10 ^ 5;
if (data != undefined && data.length > 0) { if (data != undefined && data.length > 0) {
max = data.reduce((preVal: any, item: any) => { max = data.reduce((preVal: any, item: any) => {
if (item.standardDetailScore != '') { if (item.standardDetailScore != '') {
return preVal + parseFloat(item.standardDetailScore) return preVal + item.standardDetailScore * mul;
} else { } else {
return preVal return preVal
} }
}, 0) }, 0)
} }
return max; return Math.round(max) / mul;
} }
//修改最大值 //修改最大值
export function changeHighScore(method: any, list: any) { export function changeHighScore(method: any, list: any) {