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?
LJ083198Asked:
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.

Erick37Commented:
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

Your issues matter to us.

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

Start your 7-day free trial
LJ083198Author Commented:
Sometimes the answer is so easy.....
0
caraf_gCommented:
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?

See also:
http://oldlook.experts-exchange.com/bin/Q.10113932
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.