I am currently on step 14 in the Thread Shed project in the Computer Science path. I am required to convert the sales to floats and then calculate the sum of all sales. Nearly all the floats will have 2 decimal places (0.00), though a few will have 1 (0.0), however the sum I am getting has 13 decimal places??? Can anyone tell me why this is, and how to solve it please? Thank you kindly.

It’s just a floating point error, have a look at the following queries which discuss it.

If it’s a problem you could consider working with integers for straightforward math or using certain modules such as Decimal. Arguably you could just format the string output so you don’t see the extra places but that’s a little bit more like hiding the problem (assuming it actually is a problem).

2 Likes