VBScript rounding problem, any, n/a

Can anyone tell me why this displays as "47332" instead of "47333"?

  strPrice = "47332.95"
  dPrice = cdbl(strPrice)
  lensp = len(strPrice)-3
  xprice = left(cstr(round(dprice,2)),lensp)
dcassAsked:
Who is Participating?
 
amit_gCommented:
Becuase

dPrice = cdbl(strPrice)
dPrice => 47332.95
round(dprice,2) => 47332.95
cstr(round(dprice,2)) => cstr(47332.95) => 47332.95
left(cstr(round(dprice,2)),lensp) => left(47332.95,5)
xprice = left(cstr(round(dprice,2)),lensp) => 47332

Why are you doing that? Why not just

xprice = round(strPrice, 0)
0
 
RobSampsonCommented:
amit_g is right, you are rounding
47332
because that is
47332.95 minus 3 characters

Just use the alternative that amit_g suggested and it will automatically round the number to zero decimal places.
The Round function: http://msdn2.microsoft.com/en-us/library/se6f2zfx.aspx

Regards,

Rob.
0
 
dcassAuthor Commented:
Cause I didn't know what I was doing.
Thanks, both.
0
 
RobSampsonCommented:
No problem dcass....it's all a learning process....we don't mean to come across disrepectful, we were all there once....

Regards,

Rob.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.