+ 11

Why is 0.1 + 0.2 = 0.30000000000000004 in Python?

Instead of 0.3

18th May 2018, 1:02 PM
Johannes
Johannes - avatar
5 Answers
18th May 2018, 1:09 PM
Burey
Burey - avatar
+ 9
It is also explained here: https://docs.python.org/2/tutorial/floatingpoint.html
18th May 2018, 3:40 PM
Paul
Paul - avatar
+ 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
20th May 2018, 11:39 AM
Zoetic_Zeel
Zoetic_Zeel - avatar
+ 2
Floating point. Their inaccurate.
22nd May 2018, 2:25 AM
Apple Blossom
Apple Blossom - avatar
+ 1
This is probably because 0.1 and 0.2 are floats.
19th May 2018, 1:57 PM
Siddharth
Siddharth - avatar