Currency Issue

D

David W

I have got a text box that I am putting a calculation from vb in.
The problem I am having is that the numbers I am calculating apparently have
more than 2 numbers to the right of the decimal.
Is there a way to use the numbers that already exist and in the calculations
used in vb, set how many decimals to the right.
example
I have
Me.caltotal = Me.Text31 - Me.tempcost
If Me.caltotal = 0 Then
DoCmd.GoToRecord , , acNext
Else
MsgBox "my message", vbCritical + vbOKOnly, "Conflict in Cost"
Exit Sub
End If
I have all of the textboxes set to currency with 2 decimals
If I change the decimals on me.caltotal, I get like.0069 for a result.
Some will pass some won't, even the ones that say 0.00
 
G

Guest

You might try something like this if you don't care if there is anything less
than a cent:
Dim curTemp as Currency

curTemp = CCur(Me.Text31) - CCur(Me.tempcost)
Me.caltotal = ABS(curTemp * 100) / 100
 
D

David W

Still get the same problem
me.caltotal shows $0.00 and it gives me the msg

any ideals?
 
G

Graham Mandeno

Hi David

The Currency data type does allow for a precision of four decimal places,
because some financial application require this. If you format a currency
value with two decimal places, this only changes the way the value is
displayed, not what is stored.

For example, let's say you have three textboxes:
txtAmount: currency, value $10.38
txtTaxRate: percent, value 10.0%
txtTax: currency, value =[txtAmount]*[txtTaxRate]

The value displayed in txtTax will be $1.04, but if you change the format to
four decimal places you will see what is really there is $1.038.

I suggest you first change Text31 and tempcost to display four decimal
places, and I'll bet that one of them contains some extra hidden places that
explain the result.

The best way to avoid this is to round to two decimal places the result of
every calculation which involves either a division or a multiplication by a
non-integer value.
 

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

Similar Threads


Top