for i = 0,1,0.01 do print(i) end
IT only prints up to .99 and idk why, I put this code in the command bar and it prints to .99 aswell
The issue is caused by floating point precision error. Due to the 100 addition operations you're doing, the binary value loses precision as it has a finite length and the bit-representation gets too long.
You can see the 0.99 you're getting is not exactly 0.99 with this piece of code:
for i = 0, 1, 0.01 do print(i == 0.99) end
It is generally considered a bad practice to use decimals in for loops due to this very issue. A way better idea is to simply use integers and divide them back into the decimal form if necessary:
for i = 0, 100 do i = i / 100 print(i) end
It might be a simple fix. Either:
for i = 0, 1, 0.01 do print(i + 1) end
for i = 0, 1.01, 0.01 do print(i) end
Locked by User#19524
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?