Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access calculations 2

Status
Not open for further replies.

Angelis26

Technical User
Nov 19, 2003
14
0
0
GB
Hi can anyone help? with Access 97 on Windows 98Se OS.

On adding a series of numbers in a table which were set as type "single" and fixed to 2 dec places, Access miscalculated the sum to include minute fractions i.e. 8.00+7.35 = 15.3499999975...

Does anyone know why Access 97 does this? is there a fix?

thanks in advance.
 
Round the values before storing them in the table. Even though you have a 2 decimal mask you will still be storing the full precision of values so although you see 8.00 the underlying value might be 8.004 and could appear to produce an incorrect value when you perform arithmetic operation on it. I usually do the required math and then store the rounded value. This is especially important when working with money. HTH.
 
I'm not exactly sure though I have read up on this sort of issue and what was done, the data type was converted to Currency to get around the issue. The Currency Data Type (8 bytes) actually goes out 4 decimal points.

If you are limiting the 2 decimal places via the format property, that is only dealing with how the data is displayed, thus you can still run into this issue cause the data will still be saved with all of the digits carried out as far as a Single Data type will allow (4 bytes).

Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
When the going gets tough, the tough gets going.
 
It is not "Access" that is doing it.

It is "The Computer" that is doing it.

Think about how you represent a non-integer value in a computer.
Any decimal fraction ( that is not itself a binary fraction ) will have rounding errors associated with it when it is stored.

For a single number this is not a problem because the detail to which it is stored is always greater than the detail to which it is displayed. However, when you start summing numbers with errors then you often get to the situation of noticing the differences.



By the way:-
Defining the number as SINGLE sets the number of bytes used to store the value
Fixing it to 2dp ONLY affects what is DISPLAYED
Therefore, if you have three values
a = 1.004
b = 2.004
c = 3.004
Each stored as singles and fixed at 2dp then you will see

a = 1.00
b = 2.00
c = 3.00
a + b + c = 6.01

In order to get to an answer of 6.00 you'll need
Round(a,2) + Round(b,2) + Round(c,2) = 6.00



'ope-that-'elps.




G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
Thanks for the replies. We ended up using the same method as rdodge before we saw the threads, as this seemed to be the best course of action.

But thanks to all for your threads.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top