Singe Precision field with currency format

B

Bailey

I have a table with a single precison field set with the currency format and
the decimal places limited to 2. When I open the table and place my cursor
in that field in an existing record, all of the decimal places in the field
appear while I'm editing. If I change the format to fixed this does not
occur, only the 2 decimal place digits appear. How can i get that desired
behavior with the currency format?
 
A

Allen Browne

You can't.

The Single type is a floating point number. You can format it so it only
*displays* 2 decimal places, but you cannot truncate it so that it only
contains two places because floating point numbers do not have that kind of
precision. Access will display the full contents to the user when they enter
the field. Additionally, there will always be some rounding errors with
floating point numbers.

The Currency type is not a floating point number, so it does not have the
rounding errors. It is a fixed point number, i.e. it always has 4 decimal
places. Access stores it and calculates it like a whole number and then
stuffs the decimal point in again afterwards. You can think of Access
storing $99 as the whole number 990000. Clearly this allows it to store the
number of cents (even hundredths of a cent) precisely, and there is no
rounding error because the math is integer math. It is therefore able to do
what you need.

In later versions of Access, there is another data type called Decimal, but
it is buggy and not properly implemented. Don't use it. The Decimal is a
scaled number, which you can specify the number of digits to store, and the
number of decimal places you want. Like Currency, the math is integer math,
and the decimal point is then popped back in at the end. The idea is good,
but it really is unusable. There is no Decimal type in VBA, so you must use
a Variant which has its own disadvantages and you cannot declare a constant
as a Decimal. The DAO library has not been enhanced to handle the Decimal
completely, so you must learn and work with mixed libraries, and ADOX is
very buggy. Even worse, Access cannot even sort the Decimal field properly,
so you are likely to get wrong results in your queries. More information:
http://members.iinet.net.au/~allenbrowne/bug-08.html

The best solution for you is probably to use the Currency type.
 

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