+ 11
Why is 0.1 + 0.2 = 0.30000000000000004 in Python?
Instead of 0.3
5 odpowiedzi
+ 26
i suggest you read up on this:
https://en.m.wikipedia.org/wiki/Floating-point_arithmetic
or a shorter explaination here
https://www.quora.com/Why-is-0-1+0-2-not-equal-to-0-3-in-most-programming-languages
+ 9
It is also explained here:
https://docs.python.org/2/tutorial/floatingpoint.html
+ 4
Well, I think you got the answer but if you don't want any trouble during calculations.. you can use something like this..
a = "%0.2f"%(0.1+0.2)
print(a)
where 0.2 indicates that you need answer only upto two decimal places
+ 2
Floating point. Their inaccurate.
+ 1
This is probably because 0.1 and 0.2 are floats.