Using Currency data types in IF comparisons

  • Thread starter graeme34 via AccessMonster.com
  • Start date
G

graeme34 via AccessMonster.com

Hi I have a number of currency data types that when being used in IF
comparisons are not getting what I want for instance...
a user enters a value in a text box....I then use thsi value to compare
against the currency data type...
ie user enter £353.12.....data type is actually £352.1175
is there any way to limit the currency value to only two decimal places?
 
B

Brendan Reynolds

No, you can't limit the currency data type to two decimal places. But
instead of checking for equality, you can check whether the absolute
difference between two values is below a certain minimum difference that you
consider significant. For example, the following expression will return
"True" if the absolute difference between the two values is less then .01
....

? IIf(Abs(352.12 - 352.1175) < .01, "True", "False")
True
 
G

graeme34 via AccessMonster.com

Its Ok now...have found the solution in previous posts.....
I should use the Round(currencydataname,2) prior saving any currency
 
G

graeme34 via AccessMonster.com

Brendan, thanks for your reply.....as stated in my second post.....can I not
use the Round() function....although I havent had a chance to fully test it
out it seems to be working for now.
 
B

Brendan Reynolds

It depends on your specific requirements, but the Round function certainly
might be an appropriate solution to your problem. I'll post a link below to
a search result. Some of the articles listed have information about how the
Round function behaves, and others describe how to write custom rounding
functions if the behaviour of the built-in function doesn't meet your needs.

http://search.microsoft.com/results.aspx?mkt=en-IE&setlang=en-IE&q=vba+round+function
 
G

graeme34 via AccessMonster.com

Thank you Brendan..
Brendan said:
It depends on your specific requirements, but the Round function certainly
might be an appropriate solution to your problem. I'll post a link below to
a search result. Some of the articles listed have information about how the
Round function behaves, and others describe how to write custom rounding
functions if the behaviour of the built-in function doesn't meet your needs.

http://search.microsoft.com/results.aspx?mkt=en-IE&setlang=en-IE&q=vba+round+function
Brendan, thanks for your reply.....as stated in my second post.....can I
not
[quoted text clipped - 19 lines]
 
G

Guest

'Round' has two problems:

1) It uses 'Bankers Rounding'. If you don't know what that is, you
will be surprised to see that bankers round differently than grade
school students do!

2) For a small number of all possible fractions ending in 5, 'Round'
returns the wrong value: there are rounding errors in the Windows
implementation of 'Round'

I think that using the currency data type you won't see any 'type 2'
problems, but I can't swear to it ???? (I just don't remember, but
if currency is stored as an integer type, it shouldn't have rounding
errors).

(david)
 

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