472,145 Members | 1,789 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

Errors in Currency Rounding

Is there any code available to address currency rounding problems in
Access 97? Apparently, selecting currency type table fields does not
resolve the problem. For instance, in my form I have a price of item
field (say $49.95), and a percentage discount field (say 10% = $5.00),
and calculated net cost field of the two. Access seemingly doesn't
understand banker's rules as the resulting total is $44.96. Could this
be a bug? Why does it miscalculate with currency numbers?

Thanks for your comments. Dalan
Nov 12 '05 #1
3 9235
What is your understanding of banker's rounding - that 5 is rounded towards
the EVEN number? $44.96 would seem to be the closest even number ot $44.955.

There are a (very) few cases where floating point numbers do not round as
you would expect. You can deal with those by explicitly typecasting to
Currency, i.e.:
Round(CCur([Price] * (1 - [Discount])), 2)

Since the Currency type cannot be Null, you may need Nz() inside CCur() as
well.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html

"Dalan" <ot***@safe-mail.net> wrote in message
news:50*************************@posting.google.co m...
Is there any code available to address currency rounding problems in
Access 97? Apparently, selecting currency type table fields does not
resolve the problem. For instance, in my form I have a price of item
field (say $49.95), and a percentage discount field (say 10% = $5.00),
and calculated net cost field of the two. Access seemingly doesn't
understand banker's rules as the resulting total is $44.96. Could this
be a bug? Why does it miscalculate with currency numbers?

Thanks for your comments. Dalan

Nov 12 '05 #2
OK, just call me hasty the last week or so. I was incorrect in saying it
is necessary to convert (1) to currency before subtracting a currency from
it. VBA or the expression service automatically converts to Currency in
this case. Converting the constant to currency is only necessary if the
constant is a fraction.

On Tue, 16 Sep 2003 15:54:31 GMT, Steve Jorgensen <no****@nospam.nospam>
wrote:
On Tue, 16 Sep 2003 12:33:26 GMT, "Allen Browne"
<ab***************@bigpond.net.au> wrote:
What is your understanding of banker's rounding - that 5 is rounded towards
the EVEN number? $44.96 would seem to be the closest even number ot $44.955.

There are a (very) few cases where floating point numbers do not round as
you would expect. You can deal with those by explicitly typecasting to
Currency, i.e.:
Round(CCur([Price] * (1 - [Discount])), 2)

Since the Currency type cannot be Null, you may need Nz() inside CCur() as
well.


I've found it takes more than this. Every part of the expression must be
converted to currency so, for instance, assuming [Discount] is already
currency, you need Round(CCur([Price] * (CCur(1) - [Discount])), 2). Also,
if you ever divid, you have to wrap the division in a CCur(...) or that
part of the result will be converted to Double. Note that, if you read all
Microsoft's documentation, it would seem that CCur(<currency>/<currency>)
would always produce a Double, then conver to Currency, but testing has
shown that it works more intelligently, and actually does a Currency
division in this case, never producing an intermediate Double (certain
known cases of rounding error with Double division do not occur).

Next, most companies I've worked with compute a discount amount, then
subtract that from the price rather than computing Price*(1-Discount).
Doing it this way, the discount on 49.95 is 4.995 which rounds to 5.00.
Subtracting that from 49.95 gives 44.95. When the last digit of the price
is odd, these 2 methods of calculating the discount always produce
different results. It's a question of whether you're rounding the
discounted price, or rounding the discount.


Nov 12 '05 #3
I have also had trouble with rounding in Access Currency. The internal form
of currency is scaled integer but the implementation uses 4 digits of
fraction instead of just 2 (pennies). The result is still an indefinite
rounded result.
The only perfect solution I have found was to do the scaling myself. Use
long integer format and on entry multiply each value by 100. Do this for ALL
money variables. After any division, do a suitable rounding operation,
truncate and store in the long integer form again. This is the only way I
was able to get the calculated sum of a column of numbers to agree with the
actual sum.
Hugh

"Dalan" <ot***@safe-mail.net> wrote in message
news:50*************************@posting.google.co m...
Is there any code available to address currency rounding problems in
Access 97? Apparently, selecting currency type table fields does not
resolve the problem. For instance, in my form I have a price of item
field (say $49.95), and a percentage discount field (say 10% = $5.00),
and calculated net cost field of the two. Access seemingly doesn't
understand banker's rules as the resulting total is $44.96. Could this
be a bug? Why does it miscalculate with currency numbers?

Thanks for your comments. Dalan

Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by tshad | last post: by
6 posts views Thread by Mitchell Vincent | last post: by
9 posts views Thread by Joe Attardi | last post: by
2 posts views Thread by Senna | last post: by
1 post views Thread by Eric | last post: by
2 posts views Thread by labcheung | last post: by
2 posts views Thread by Smokey Grindel | last post: by
reply views Thread by Saiars | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.