To add to what Albert said,
if you do have real numbers for data types that you want to compare, use
an inequality instead of an equality...for instance,
instead of
If a = b then
use
If Abs(a-b) < 0.001 then 'or whatever is your tolerance
Warm Regards,
Crystal
*
(: have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
Albert D. Kallal wrote:
> Actally, one of the first lessons you lean in compter scicne is that "real"
> numers on a computer are ONLY an aprpociaztion.
>
> hence:
>
> 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 addtions..already rounding is occuring
>
> and if we add the follwing 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 somthing else"
> endif
>
>
> The above will actuall produce:
>
> the number is something else
>
> NOTE VERY careful in the above how the actual debug.print produced 10.1, and
> DOES NOT show any rounding errors..but in fact the test condition "= 10.1"
> FAILS!!!!
>
> So, any serious software design has to take into account that real numbers
> can't be represented exactly in a computer. For most stuff this is not a
> problem, but when you write any software that will do financial
> calculations, then you must be VERY aware of rounding issues, and that
> single, or double numbers in a computer will rapidly result in rounding
> problems. "3/10th" in a computer is only an approximation of 3 over 10. That
> even applies to "1 over 10". You can't reliblairy use conditations on
> single, or double numbers in code....they will simply fail more often then
> not!!
>
>