diff --git a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java index 198a4ede..a0ae0651 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java @@ -1786,12 +1786,15 @@ public class ApplicationDao { String expression = formula; for (String variable : variables) { Double value = variableValues.get(variable); - if (value != null) { - // Replace {variable} with its corresponding value in the formula - expression = expression.replace("{" + variable + "}", String.valueOf(value)); - } - } + String placeholder = "{" + variable + "}"; + // If value is null, use 0 instead + String replacement = String.valueOf(value != null ? value : 0); + expression = expression.replace(placeholder, replacement); + } + if (expression.matches(".*\\{.*\\}.*")) { + return 0; + } // Step 4: Evaluate the mathematical expression return Utils.evaluateExpression(expression); }