fix(性能测试): 多节点配置自定义占比时浮点数相加精度问题修改

This commit is contained in:
CaptainB 2023-08-22 10:47:22 +08:00 committed by 刘瑞斌
parent 4a784ee1ae
commit 71784c3218
1 changed files with 8 additions and 1 deletions

View File

@ -708,6 +708,13 @@ export default {
this.$emit('changeActive', '1');
return false;
}
//
let add = function(num1, num2) {
const num1Digits = (num1.toString().split('.')[1] || '').length;
const num2Digits = (num2.toString().split('.')[1] || '').length;
const baseNum = Math.pow(10, Math.max(num1Digits, num2Digits));
return (num1 * baseNum + num2 * baseNum) / baseNum;
}
for (let i = 0; i < this.threadGroups.length; i++) {
let tg = this.threadGroups[i];
tg.durationHours = tg.durationHours || 0;
@ -722,7 +729,7 @@ export default {
this.customNodeChange(tg);
let sum = tg.resourceNodes.map(n => n.ratio).reduce((total, curr) => {
total += curr;
total = add(total, curr);
return total;
}, 0);
if (sum !== 1) {