Fixed issue of formula calculation in application
This commit is contained in:
@@ -1792,10 +1792,14 @@ 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
|
||||
|
||||
Reference in New Issue
Block a user