such code in VBScript will return wrong result:
MsgBox Round(4.99985,4)
It will return 4.9998 but correct result is 4.9999. I know that it is related to how VBScript works with numbers with floating points, that some numbers can’t be represented in binary system, but please tell me:
- What exactly happening here?
- What is the possible workaround for that?
Thanks!
This is expected result, so called bankers’ rounding. Check out the description of the
Roundfunction (bold added by me):To round to larger, you can use the following function (taken from here):
(Note: Negative numbers are rounded down.)