Why doesn't Access always add properly? 
Author Message
 Why doesn't Access always add properly?

When summing more than two real numbers whose total should be zero,
sometimes a very small non-zero number is returned by the calculation
instead of the expected zero.  I suspect that the problem lies in how
Access/VB represent and handle real numbers internally, perhaps leading to
overflow at some point in the calculation.

This problem occurs in Access 2.0, Access 97, and VB4, which leads me to
suspect that it's not really a bug, but rather I'm missing something subtle
in dealing with real number calculations.

The following examples that were run in the immediate window in Access 2.0
(they occur in Access 97 and VB4 also)

? 2.11 -  1.11 - 1
-2.22044604925031E-16

?  973134 - 1082907.222  +  109773.222
-7.27595761418343E-11

Note: it doesn't happen for all examples of this type (why????)
?2.12 - 1.12 - 1
0

1.) Does anyone know why it's doing this or where could I find an answer ?

2.) What is the best solution to the problem ?

3.) Why doesn't it happen for all cases ?

I've come up with two ideas for working around the problem
1.) Using the Format function to round the results of the calculation down
to a reasonable number of digits.

? Format( 973134 - 1082907.222 +  109773.222 ,"#.00000000")
.00000000

2.) Breaking the calculation into two separate steps
    ? 973134 - 1082907.222
    -109773.222

    ?-109773.222 +  109773.222
    0

This is a problem in a financial report that I'm working on where the
calculation that is of the form
A= B/(C-D+E)  where if (C-D+E) is zero then A should be 0.  What happens is
when (C-D+E) is very small, due to the failure in the calculation above, but
not zero then A becomes very large which is wrong.


that would be great.

Thanks to all.



Fri, 02 Jun 2000 03:00:00 GMT  
 Why doesn't Access always add properly?

Check on the MS Access Developer website file page, or on the FMS Inc web
site, for an article on this topic entitled "When Access Math Doesn't Add
Up" by Luke Chung as published in Smart Access.  It will answer all your
questions.
--
Pete B



Quote:
> When summing more than two real numbers whose total should be zero,
> sometimes a very small non-zero number is returned by the calculation
> instead of the expected zero.  I suspect that the problem lies in how
> Access/VB represent and handle real numbers internally, perhaps leading
to
> overflow at some point in the calculation.

> This problem occurs in Access 2.0, Access 97, and VB4, which leads me to
> suspect that it's not really a bug, but rather I'm missing something
subtle
> in dealing with real number calculations.

> The following examples that were run in the immediate window in Access
2.0
> (they occur in Access 97 and VB4 also)

> ? 2.11 -  1.11 - 1
> -2.22044604925031E-16

> ?  973134 - 1082907.222  +  109773.222
> -7.27595761418343E-11

> Note: it doesn't happen for all examples of this type (why????)
> ?2.12 - 1.12 - 1
> 0

> 1.) Does anyone know why it's doing this or where could I find an answer
?

> 2.) What is the best solution to the problem ?

> 3.) Why doesn't it happen for all cases ?

> I've come up with two ideas for working around the problem
> 1.) Using the Format function to round the results of the calculation
down
> to a reasonable number of digits.

> ? Format( 973134 - 1082907.222 +  109773.222 ,"#.00000000")
> .00000000

> 2.) Breaking the calculation into two separate steps
>     ? 973134 - 1082907.222
>     -109773.222

>     ?-109773.222 +  109773.222
>     0

> This is a problem in a financial report that I'm working on where the
> calculation that is of the form
> A= B/(C-D+E)  where if (C-D+E) is zero then A should be 0.  What happens
is
> when (C-D+E) is very small, due to the failure in the calculation above,
but
> not zero then A becomes very large which is wrong.

> I appreciate any help.  If you could also e-mail a reply to


- Show quoted text -

Quote:
> that would be great.

> Thanks to all.



Sat, 03 Jun 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Why doesn't OWA display this properly?

2. Why doesn't refresh always refresh?

3. Why doesn't refresh always refresh?

4. Access 2000 Form Doesn't Repaint Properly!

5. Add-Ins, why doesn't it work ???

6. Form doesn't display properly on user's PC

7. Email won't always format properly

8. Why oh why doesn't this work?

9. Documenter doesn't work properly in A2K

10. Form control doesn't repond properly?

11. Outlook doesn't properly start on external activation

12. Select method doesn't work properly

 

 
Powered by phpBB® Forum Software