Why do the following two calls to the Fix
function produce different results?
Private Sub Test_Fix()
Dim d As Double
d = -17.555
Debug.Print "Fix(" & d & " * 1000) = " & Fix(d * 1000)
d = d * 1000
Debug.Print "Fix(" & d & ") = " & Fix(d)
' Output:
' Fix(-17.555 * 1000) = -17554
' Fix(-17555) = -17555
End Sub
The second of the two calls give the result I would expect.
I assume the difference has something to do with inexact representation of some numbers as type Double
, whereby the first call would actually compute something like Fix(-17.554999999)
. However, it still seems the two should produce consistent results since the d
is of type Double
.
The documentation mentions that the parameter can be
A number of type Double or any valid numeric expression.
Therefore, I would have assumed that both function calls above would be valid and produce identical results.