rounding

G

Guest

I have a form with a command button which does the following:
[bprice] = [rprice] * 0.77

[rprice] is $12.50 and when you do the above, [bprice] is 9.625

It works fine. When you view the field it shows 9.63 but when you click
into the field, it expands to 9.625. How can I have the actual value be
9.63? What is going on here? I guess rounding.

Thanks.
 
G

Guest

Rounding will do it, but you will not always get what you expect. In the
real world when we round a number, any decimal >= 5 will round the the number
to the left of it up one and < 5 rounds down 1.

VBA doesn't do it quite like that. Depending on the number to the left of
the digit to be rounded off, it may round up and it may round down. The
reason is, over a large set of data, the total will proabably be over stated,
so the rounding algorithm is different.

In this case, 9.625 actually rounds to 9.62
If you can live with that, all that is needed is

[bprice] = Round([rprice] * 0.77, 2)

If you want it to go up to 9.3, you can fool it by using the Format function
which converts it to a string and the CSng function to turn it back to a
single presicion data type or CDbl if that is the field type.

[bprice] = CSng(Format([rprice] * 0.77,"#,##0.00"))
 

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

get query values 4
Currency Field 5
Rounding decimal values in forms and reports 2
Percent value rounds up in Access 1
Create Table 2
Form: remove number rounding 1
Round() Function 2
Round() 3

Top