-
Solved: Need help with looping function and Rounding issue
I have a loop that increments a fractional number. In the first case (0,2 step .4) it works as desired, with 2 included. In the second case (3,5 step .4), it skips 5.
What is the basis for this difference, or is there a bug? What is the work-around?
[VBA]Sub testLoopInc()
Dim Min As Double, Max As Double, Inc As Double
Dim d As Double
Min = 0#
Max = 2#
Inc = 0.4
d = Min
Debug.Print "0 to 2 , step .4"
Do While d <= Max
Debug.Print d
d = d + Inc
Loop
Debug.Print "now 3 to 5 , step .4"
Min = 3#
Max = 5#
Inc = 0.4
d = Min
Do While d <= Max
Debug.Print d
d = d + Inc
Loop
d = Min
End Sub[/VBA]
-
Nevermind. I guess this is just standard floating point issue. I made workaround that doesn't increment by floats..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules