+ 1

Why are calculations in Python wrong? (SOLVED)

When I type 3.3- 3, the answer is not 0.3 but 0.299 something. Same with 2.2-2 etc. What exactly is wrong? Why is this happening?

20th Oct 2020, 2:58 PM
Pratha Nagpal
Pratha Nagpal - avatar
2 odpowiedzi
+ 5
This is because of famous floating point error (occurs in almost all languages that support floating point arithmetic) Read this for more info about it👇 https://docs.python.org/2/tutorial/floatingpoint.html
20th Oct 2020, 3:42 PM
Arsenic
Arsenic - avatar
+ 2
Thank you so much for this.
20th Oct 2020, 4:01 PM
Pratha Nagpal
Pratha Nagpal - avatar