Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
jdolier
Starting Member
2 Posts |
Posted - 2008-07-24 : 18:09:38
|
| I am trying to run a while loop that goes from 0.0 to 2.0, so I used the following basic structure:declare @counter floatdeclare @limit floatset @counter = 0.0set @limit = 2.0while (@counter <= @limit)begin -- Do stuff set @counter1 = @counter1 + .01endFor some reason, the @counter only gets to 1.99. When it gets to 2.0 it exits the loop. I know that I could simply increase the limit to make it work, but I want to know why this problem occurs. To help trouble shoot, I created two loops, one with equality and one without. It turns out that when I set the counter variable to 1.63 or higher, the equality loop works fine (goes to 2.0), but when I set it between 0.0 and 1.62 it only goes to 1.99. Why is this?(I included my loop code below)declare @counter1 floatdeclare @counter2 floatdeclare @limit floatset @counter1 = 1.62set @counter2 = 1.62set @limit = 2.0while (@counter1 <= @limit)begin if (@counter1 > 1.9) print 'Loop w/ Equality: Counter(' + cast(@counter1 as varchar) + ')' set @counter1 = @counter1 + .01end while (@counter2 < @limit)begin if (@counter2 > 1.9) print 'Loop w/o Equality: Counter(' + cast(@counter2 as varchar) + ')' set @counter2 = @counter2 + .01end |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
jdolier
Starting Member
2 Posts |
Posted - 2008-07-24 : 20:16:22
|
| Worked like a charm. Thank you! |
 |
|
|
|
|
|