weird integer rounding error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • madmike19
    New Member
    • Nov 2007
    • 1

    weird integer rounding error

    hi guys why does this

    Dim x As Integer
    Dim y As Double

    y = 4.664
    x = Convert.ToInt32 (y)

    give me x=5 ?????

    surely it should be 4

    it doesnt matter what conversion i do all my integers round up if above .5 and down if below .5

    any ideas ? ? ? ?
  • Mohan Krishna
    New Member
    • Oct 2007
    • 115

    #2
    Originally posted by madmike19
    :
    :
    any ideas ? ? ? ?
    Hi

    Why don't u use INT()?

    ALL THE BEST!

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      What this code is doing is rounding. From the sound of it, you don't want rounding, you want truncation. As Mohan mentioned, the Int() function may be the way to go. (This applies to VB6 - not sure about your version.)

      Comment

      Working...