Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

VS 2008 [RESOLVED] Explain This Strange Mathematical Odity in VS2008!!!

$
0
0
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?

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>