修正数据错误
This commit is contained in:
@@ -325,9 +325,14 @@ func (r *recipeGenerateManagerImpl) GenerateRecipe(ctx context.Context, pigType
|
||||
// 二次校验: 确保实际原料总量不超过 100% (允许小于100%因为填充料被移除)。
|
||||
// 允许略微超过100%的浮点误差,但不能显著超过。
|
||||
if totalPercentage > 1.0+1e-3 {
|
||||
return nil, fmt.Errorf("计算结果异常:实际原料总量超过 100%% (计算值: %.4f),请检查算法或数据配置", totalPercentage)
|
||||
return nil, fmt.Errorf("计算结果异常:实际原料总量超过 100%% (计算值: %.2f),请检查算法或数据配置", totalPercentage)
|
||||
}
|
||||
// 如果 totalPercentage 小于 1.0,说明填充料被使用,这是符合预期的。
|
||||
// 此时需要在描述中说明需要添加的廉价填充料的百分比。
|
||||
if totalPercentage < 1.0-1e-4 { // 允许微小的浮点误差
|
||||
fillerPercentage := (1.0 - totalPercentage) * 100.0
|
||||
recipe.Description = fmt.Sprintf("%s。注意:配方中实际原料占比 %.2f%%,需额外补充 %.2f%% 廉价填充料", recipe.Description, totalPercentage*100.0, fillerPercentage)
|
||||
}
|
||||
|
||||
return recipe, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user