Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Int() Function MS Access VBA

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?

like image 958
Johan van der Slikke Avatar asked Sep 05 '25 03:09

Johan van der Slikke


2 Answers

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

like image 92
html_programmer Avatar answered Sep 07 '25 19:09

html_programmer


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 
like image 45
4dmonster Avatar answered Sep 07 '25 19:09

4dmonster