Can some one explain this irregularity, try it yourself
Dim BatchTotal As Double = 457.34
Dim FirstAmount As Double = 214.00
Dim SecondAmount As Double = 243.34
Dim Totals As Double = FirstAmount + SecondAmount
If Totals > BatchTotal Then
MsgBox("Amounts Are Greater")
MsgBox(Totals)
MsgBox(BatchTotal)
MsgBox(Totals - BatchTotal)
Else
MsgBox("Not Greater")
End If
What you would expect is the message box 'Not Greater'
but instead you will see that it compares 457.34 with 457.34 and recons that they do not match
I know that someone will come back and say that you should be using single precision numbers
because if you change to single precision then you won't have this problem.
The problem with that is these values could be anything from a couple of cents to Millions of Dollars.
Single precision values tend to round off after a certain level and the results that are returned on high value
numbers may be inaccurate.
Any Ideas?
Dim BatchTotal As Double = 457.34
Dim FirstAmount As Double = 214.00
Dim SecondAmount As Double = 243.34
Dim Totals As Double = FirstAmount + SecondAmount
If Totals > BatchTotal Then
MsgBox("Amounts Are Greater")
MsgBox(Totals)
MsgBox(BatchTotal)
MsgBox(Totals - BatchTotal)
Else
MsgBox("Not Greater")
End If
What you would expect is the message box 'Not Greater'
but instead you will see that it compares 457.34 with 457.34 and recons that they do not match
I know that someone will come back and say that you should be using single precision numbers
because if you change to single precision then you won't have this problem.
The problem with that is these values could be anything from a couple of cents to Millions of Dollars.
Single precision values tend to round off after a certain level and the results that are returned on high value
numbers may be inaccurate.
Any Ideas?