Fixed formula calculation issue in application

This commit is contained in:
rajesh
2025-07-29 17:33:17 +05:30
parent 9354a3bca8
commit 7b5ef30c7d

View File

@@ -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);
}