?
Solved

VBScript rounding problem, any, n/a

Posted on 2007-08-07
4
Medium Priority
?
938 Views
Last Modified: 2013-11-05
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)
0
Comment
Question by:dcass
  • 2
4 Comments
 
LVL 58

Accepted Solution

by:
amit_g earned 600 total points
ID: 19648704
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
 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 400 total points
ID: 19650760
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
 

Author Comment

by:dcass
ID: 19650902
Cause I didn't know what I was doing.
Thanks, both.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 19650919
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…

616 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question