I'm implementing the AsymArith round method from http://support.microsoft.com/kb/196652
Now I run into a strange issue with the Int() function: it is supposed to only strip the fractional part, but it changes the integer portion as well.
? 131.415 * 100 + 0.5
13142
? Int(131.415 * 100 + 0.5)
13141
Can someone explain why the Int() function changes the result of the expression?
It is related to the internal rounding mechanism of the int function.
Try for example:
print Int(131.415 * 100 + format(0.5, "0.00"))
When explicitly setting the rounding yourself, you will get the expected result.
I would refer to do this article:
http://support.microsoft.com/kb/214118
probably it's Immediate window's magic caused by type cast(dispite ?typename(131.415 * 100 + 0.5 ) is Double)
?int(cdbl(131.415 * 100 + 0.5 ))
13142
Public Sub test_int()
Dim t As Double
t = 131.415 * 100 + 0.5
Debug.Print t
Debug.Print Int(t)
End Sub
13142
13142
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With