Python 3 Cheapest Shipping

I was doing this assignment:
https://www.codecademy.com/courses/learn-python-3/projects/python-sals-shipping

And was just wondering why the drone shipping gives such a weird value with all the decimal places?
$ 43.199999999999996

The calculation is 9 * 4.8, shouldn’t it just equal to 43.2?

Unfortunately it’s a rather generic problem, you can read about floating point on wikipedia or otherwise and the python docs cover it fairly clearly (and offers a few options for cleaner representation): 15. Floating Point Arithmetic: Issues and Limitations — Python 3.9.4 documentation

3 Likes