So it was late at night and I was hacking away at my touch-controls for my UnicornHat. I was trying to set the brightness in nine steps between 0.1 and 0.9. When all of a sudden, this happened:
>>> foo=0.1 >>> foo+=0.1 >>> print(foo) 0.2 >>> foo+=0.1 >>> print(foo) 0.30000000000000004
So according to my internal senses this looked not very precise. But according to the almighty Stackoverflow and one of my beloved coworkers who can indeed speak ASM fluently, this is in fact very precise (for a float). Since a float is merely a value, lets say, close by the one you wished it to be.
So for everyone who believed 0.3 was 0.3 and not a value very close to 0.3 please to not be scared, there’s a different datatype for the rescue, that can (if you believe it) store 0.3 as real value.
So if you’re into things being mathematically correct and not correct according to the datatype, you might want to give either the ‘Decimal’ datatype a chance or add a `round(your-number, digits)` to everything you want to be precise.