I am adding a float value in an integer using loops but the answer is different. Here is my code:
import time
test = 0
while True:
test += 0.0001
print(test)
time.sleep(0.3)
When I ran it I should have got:
0.0001
0.0002
0.0003
0.0004
0.0005
.........
But I got:
0.0001
0.0002
0.00030000000000000003
0.0004
0.0005
0.0006000000000000001
0.0007000000000000001
0.0008000000000000001
0.0009000000000000002
0.0010000000000000002
0.0011000000000000003
0.0012000000000000003
Why it is so and how to solve this problem?