Dec-27-2021, 10:30 AM
A few weeks ago I wanted to simply print the outcome of some calculations, just as a reference at that moment. But ever since I am still wondering why some of the results has 16 decimals with the last result not exactly 0. It was a calculation as below, but it happens with other decimals too: not only 0.4.
for item in range(10): print(item * 0.4)
Output:0.0
0.4
0.8
1.2000000000000002
1.6
2.0
2.4000000000000004
2.8000000000000003
3.2
3.6
It might be explainable, maybe even mathematical, but I still can't figure out why this happens. Someone has an idea?
- Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid. Albert Einstein