
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.