I knew this, but still got bitten anyway. Great way to start the year
For this code
Dim FirstDoubleVar As Variant
Dim SecondDoubleVar As Variant
FirstDoubleVar = 8.0
SecondDoubleVar = 8.2
If ((FirstDoubleVar \ 1) = FirstDoubleVar) Then
System.DebugLog "FirstDoubleVar Is Whole"
else
System.DebugLog "FirstDoubleVar Is Not Whole"
End If
If ((SecondDoubleVar \ 1) = SecondDoubleVar) Then
System.DebugLog "SecondDoubleVar Is Whole"
else
System.DebugLog "SecondDoubleVar Is Not Whole"
End If
Dim FirstDouble As Double
Dim SecondDouble As Double
FirstDouble = 8.0
SecondDouble = 8.2
If ((FirstDouble \ 1) = FirstDouble) Then
System.DebugLog "FirstDouble Is Whole"
else
System.DebugLog "FirstDouble Is Not Whole"
End If
If ((SecondDouble \ 1) = SecondDouble) Then
System.DebugLog "SecondDouble Is Whole"
else
System.DebugLog "SecondDouble Is Not Whole"
End If
If ((FirstDoubleVar.DoubleValue \ 1) = FirstDoubleVar.DoubleValue) Then
System.DebugLog "FirstDoubleVar.DoubleValue Is Whole"
else
System.DebugLog "FirstDoubleVar.DoubleValue Is Not Whole"
End If
If ((SecondDoubleVar.DoubleValue \ 1) = SecondDoubleVar.DoubleValue) Then
System.DebugLog "SecondDoubleVar.DoubleValue Is Whole"
else
System.DebugLog "SecondDoubleVar.DoubleValue Is Not Whole"
End If
The result is
FirstDoubleVar Is Whole
SecondDoubleVar Is Whole
FirstDouble Is Whole
SecondDouble Is Not Whole
FirstDoubleVar.DoubleValue Is Whole
SecondDoubleVar.DoubleValue Is Not Whole
So even though SecondDoubleVar is 8.2, the code says it is whole.
as far as I can tell the following line
If ((SecondDoubleVar \ 1) = SecondDoubleVar) gets interpreted the following way
SecondDoubleVar \ 1 is an integer
Therefore we compare by converting the second part (SecondDoubleVar) to integer
and then we compare
so we compare 8 (SecondDoubleVar \ 1) with 8 (the converted integer value of SecondDoubleVar)
Since 8 is 8, we can conclude that 8.2 is whole
Of course, if you force the variants to Doubles (SecondDoubleVar.DoubleValue) before you make the comparison, you don’t have this problem.