Fixed issue of formula calculation in application

This commit is contained in:
rajesh
2025-07-29 17:44:07 +05:30
parent 7ebecee2b5
commit 517a8da925

View File

@@ -1792,10 +1792,14 @@ public class ApplicationDao {
String expression = formula; String expression = formula;
for (String variable : variables) { for (String variable : variables) {
Double value = variableValues.get(variable); Double value = variableValues.get(variable);
if (value != null) { String placeholder = "{" + variable + "}";
// Replace {variable} with its corresponding value in the formula
expression = expression.replace("{" + variable + "}", String.valueOf(value)); // 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 // Step 4: Evaluate the mathematical expression