# rounding

Dim A,B,C as double
B = 5000
C = 400000

A= Round(B/ C,3)
A = .0125  When I round it three places though, I get .012  What I want is .013  When I use this line of code instead
A= Round(CSng(B/ C,3) I get the desired result of A = .013

Is this the correct way to get the numbers to round up?
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
Avoid evaluations inside of functions.  Small rounding errors will result.  Instead, do your calculation first, then pass the result to Round().

Dim A As Double, B As Double, C As Double, D As Double
B = 5000
C = 400000
D = B / C
A = Round(D, 3)

Related MS article:

http://support.microsoft.com/support/kb/articles/Q195/6/57.ASP
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
Sometimes the answer is so easy.....
0
Commented:
Have fun....

Try this:

MsgBox Round(1 / 2, 0)
MsgBox Round(3 / 2, 0)
MsgBox Round(5 / 2, 0)
MsgBox Round(7 / 2, 0)
MsgBox Round(9 / 2, 0)

Result: 0, 2, 2, 4, 4

Great eh?