Apr-29-2020, 02:32 PM
Hi,
whenever i run the below loop as part of a code
x=0.
while(x<=2):
x+=.1
print(x)
i am getting the following result. why it is not accurately increasing by .1? i am a beginner. anyone could help please..
.1
0.2
0.30000000000000004
0.4
0.5
0.6
0.7
0.7999999999999999
0.8999999999999999
0.9999999999999999
1.0999999999999999
1.2
1.3
1.4000000000000001
1.5000000000000002
1.6000000000000003
1.7000000000000004
1.8000000000000005
1.9000000000000006
2.0000000000000004
i am using python 3.7 with pycharm 020
whenever i run the below loop as part of a code
x=0.
while(x<=2):
x+=.1
print(x)
i am getting the following result. why it is not accurately increasing by .1? i am a beginner. anyone could help please..
.1
0.2
0.30000000000000004
0.4
0.5
0.6
0.7
0.7999999999999999
0.8999999999999999
0.9999999999999999
1.0999999999999999
1.2
1.3
1.4000000000000001
1.5000000000000002
1.6000000000000003
1.7000000000000004
1.8000000000000005
1.9000000000000006
2.0000000000000004
i am using python 3.7 with pycharm 020