Brand New to NCalc.
I have a formula to be evaluated and Im getting some unexpected (to me) results.
The @T_No_Starters parameter used = 12.
If the formula is if (@T_No_Starters >= 8 ,'T','F')
Result FALSE
If the formula is if (@T_No_Starters >= 8.0 ,'T','F')
Result TRUE
If the formula is if (@T_No_Starters >= 10 ,'T','F')
Result TRUE
Im not sure what is going on, why is 8 False yet 8.0 is True but 10 which is again a whole number is True? How can I ensure that the evaluation is always correct? Do I turn every number into decimal? Can I set something like a parameter type? WHen Im entering my parameters?
Below is the test code I use to arrive at the above.
Private Sub Button40_Click(sender As Object, e As EventArgs) Handles Button40.Click
Dim FormulaLine As String = "if (@T_No_Starters >= 8 ,'T','F')"
Dim Parms As New Dictionary(Of String, String)
Parms.Add("T_No_Starters", 12)
Dim OurAnswer = FormulaCalculator.MSGBOXEval(FormulaLine, Parms)
End Sub
Function MSGBOXEval(Formula As String, Parms As Dictionary(Of String, String))
Try
Dim X As New Expression(Formula)
For Each key As String In Parms.Keys
X.Parameters.Add(key, Parms.Item(key))
Next
Dim result = X.Evaluate
MessageBox.Show(result)
Return result
Catch ex As Exception
MessageBox.Show(ex.Message)
Return "Error " & ex.Message
End Try
Return 0
End Function
I would best like to NOT change the values in the formula to decimal. Greater then or equal 8 starters not 8.0. It just doesen't look right. The Parameter dictionary is of string and string, I have to use it as some are strings. Is it as simple as making sure that the parameter is value when a value is required?