MS Access - rounding numbers to the nearest 0.005

G

Guest

I am working on a solution for a company that needs to measure the weight of
individual fowl to the nearest 0.005 Kgs. I have decided to use MS Access as
the platform for the development. I have encountered problems so far with
validation rules.

With field type Number, field size Single and format Fixed, validation rule:

Like "*.**0" or Like "*.**5"

Thus far this validation rule has failed to work entirely - If I were to
enter 6.000, I would get a validation error.

Can anyone provide a suitable validation rule, or point me in the right
direction?

Many thanks in advance,
Stephen Morris
 
V

Van T. Dinh

Like is a String comparison operator so I don't recommend in this case.

Another problem is that your decimal number is actually converted to binary
representation and stored in binary digits. Thus, you will need to allow
for truncation / rouding errors.

IMHO, Decimal data type may be more appropriate in this case.

My guess is the validation rule should be something like:

Abs( [YourField] * 200.0 - CInt([YourField * 200) ) < {some suitable small
number}
 

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