We have code like
ncalcFormula = "[OD1000]=[OD1100]+[OD1200]+[OD1350]+[OD1450]"
var expression = new Expression(ncalcFormula);
foreach (FormulaParameter fp in parsedParameters)
{
expression.Parameters[fp.QuestionKey] = fp.Value;
}
object res = expression.Evaluate();
Original expression :- [OD1000]=[OD1100]+[OD1200]+[OD1350]+[OD1450]
After Evaluate called Parsed expression :- {([OD1000])= (((([OD1100])+ ([OD1200])+ ([OD1350])+ ([OD1450])}
Tested with adding parameter values as follows
1) 9.33 = 2.25 + 3.25 + 1.5 + 2.33
2) 15617031.48 = 15226149.36 + 166208.00 + 0.00 + 224674.12
After evaluate 1) will return true and 2) will return false though both expression are correct.
Please suggest.
Using 'equlas' operator to compare float values is a bad idea since result of calculations has to be fitted into float representation. IN order to perform comparison correctly you need to specify tolerance, i.e. how much the result can diverge from the intended value. I rewrote your formula a bit to add some 'tolerance'.