none
VBA: Strange Int() and Fix() function behavior. RRS feed

  • Question

  • Dim d1 As Double
    Dim d2 As Double
    Dim d3 As Double
    d1 = 0.25
    d2 = 0.0125
    d3 = d1 / d2
    Debug.Print Int(d3) ' 20
    Debug.Print Int(d1 / d2) ' 19
    What gives? Fix() has the same issue.
    Thursday, July 27, 2017 6:10 PM

All replies

  • That's a IEEE 754 issue, try this:

    Sub test()
      Dim d1 As Variant
      Dim d2 As Variant
      Dim d3 As Variant
      d1 = 0.25
      d2 = 0.0125
      d3 = d1 / d2
      Debug.Print Int(d3)
      Debug.Print Int(d1 / d2)
    End Sub

    Andreas.

    Thursday, July 27, 2017 7:11 PM