Maybe issue is not new to you but it is very serious to my opinion not
knowing when you can trust software it gives the correct answers.
Computers have limitations, and users should be aware of such
limitations (but, in reality, very few users are). It is and has been
since the early years a standard programming practice to test for a
very small difference and if that difference is less than some
threshold, consider the result equal. Your example could be rewritten
as
If Abs((16.51 - 16) = ((1651 - 1600) / 100)) < 0.000001 Then
MsgBox "Ok"
Else
MsgBox "Error"
End If
In this code, a difference less than 0.000001 is considered equality.
Many programming languages define a constant for this threshold, but
VB/VBA does not.
Such limitations exist in the real world as well. Consider
(1/3)+(1/3)+(1/3)
If you calculate this to any finite number of decimal places, it will
never equal 1. No matter what, it will calculate to 0.999..... which
is certainly not 1. Are the foundations of Arithmetic flawed? No, it
is a computational limitation, and isn't "wrong" in any sense.
If you do the math symbolically (and there are programs that do this,
at the expense of performance), you can achieve equality. But if you
calculate the (1/3) values, you'll never get the "right" result. The
world has gotten along rather well over the last few thousand years
with "problems" like this.
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)