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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Erick37Connect With a Mentor 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
 
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
All Courses

From novice to tech pro — start learning today.