Problems with decimal places

P

paul

I have created an update query which updates a table with the result of a
calculation , the field in the table that stores the calculation is to 9
decimal places despite me putting its format as standard to 2 decimal places
in the table.

This is therefore creating problems when I try and match data to this field

Any ideas how I can stop this from happening?
 
K

Ken Snell

Try changing the expression for "Update To:" to include this syntax:

CDbl(Format("CalculationGoesHere", "0.000000000"))
 
K

Ken Snell

I think I misread your post. What you're wanting is to store just two
decimal places in the field's value?

The "2 decimal places" that you've set for the field is just the format for
the display. It doesn't affect what the actual number is.

When comparing decimal numbers, you must be careful when trying to do direct
comparisons. Computers don't store decimal numbers exactly. Thus, you may
not find a match even for a number such as 4.00, as it actually may be
stored as 3.99999994 or something like that.

Two things:
(1) You can change the way you calculate the value before storing it into
the table by using rounding-type functions to truncate the number to just
two decimal places:
"UpdateTo:" CLng((..put calculation here..) * 100) / 100

(2) When you do comparisons, I usually take the difference between the
field's value and the number to which I'm comparing, and then check if the
difference is less than some number that represents zero (such as 0.00001).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top