I am doing VBA coding in Excel 2007.
I want to add 0.1 when tm is < 5 and add 0.25 when tm is at least 5, and some other cases. In the following code, when in 3rd iteration, the expression (tm < 5)
is evaluated true when tm = 5. What is going on?
Even more interesting, if you try starting tm = 4.9, the evaluation would be correct!
Sub test()
Dim i As Integer
Dim tm As Double
tm = 4.8
For i = 1 To 5
MsgBox tm & " " & (tm < 5)
If tm < 2 Then
tm = tm + 0.05
ElseIf tm < 5 Then
tm = tm + 0.1
Else
tm = tm + 1
End If
Next i
End Sub