When we convert a float to integer in visual basic 6.0, how does it round off the fractional part? I am talkin about the automatic type conversion.
If we assign like
Update: After some googling, I came across the following article:
It is not a "bug", it is the way VB was designed to work. It uses something known as Banker's rounding which, if the number ends in exactly 5 and you want to round to the position in front of the 5, it rounds numbers down if the number in front of the 5's position is even and rounds up otherwise. It is supposed to protect against repeated calculation using rounded numbers so that answer aren't always biased upward. For more on this issue than you probably want to know, see this link
http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q196652
This explains the (apparent) weird behavior:
Cint(5.5) 'Should be 6'
Cint(8.5) 'Should be 8'
Old Update:
Perhaps you should be more explicit: use CInt
, instead of simply assigning a float to an integer. E.g:
Dim i as Integer
i = CInt(5.5)
MsgBox i