Public Sub TestAdd()
Dim MyNumber As Single
Dim i As Integer
For i = 1 To 10
MyNumber = MyNumber + 1.01
Debug.Print MyNumber
Next i
End Sub
Here is the actual outpput of the above:
1.01
2.02
3.03
4.04
5.05
6.06
7.070001
8.080001
9.090001
10.1
You can see that after just 7 additions..already rounding is occurring
and if we add the following line of code to the end of the above:
if MyNumber = 10.1 = True then
msgbox "the number is 10.1"
else
msgbox "the number is something else"
endif
The above will actually produce:
the number is something else
It turns out that when using "real" numbers, the computer standard to store
these numbers is ONLY an approximation of the value. (this is one of the
first things you learn in a computing class!!!).
So, if you don't want rounding issues, then don't use double, or single
"real" numbers.
If you only need 2, or 4 decimal places then use the currency format, as it
is an actual integer, and will not suffer the rounding issue...
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
(E-Mail Removed)