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