Python 3.7.3 (default, Apr 3 2019, 05:39:12)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> x = 9.12
>>> print (x * 100)
911.9999999999999
Conversation
Replying to
>>> import decimal
>>> decimal.Decimal("9.12")*100
Decimal('912.00')
>>> str(decimal.Decimal("9.12")*100)
'912.00'
>>> float(decimal.Decimal("9.12")*100)
912.0
>>>
1
1
Replying to
I get it his floating point related -- do you know why it works for 9.14 - 9.19 and gives the correct value but not for 9.12 and 9.13?
This website helped me understand this whole floating point weirdness: float.exposed/0x4111eb85
It’s the companion to this great explainer by :
ciechanow.ski/exposing-float
1
You'd probably get a clue onto why 9.12 is special if you converted it to it's bit representation. It's probably right on the edge. The fact that 912 divides evenly into 2^4 suggests this. I'll check into it next time I'm by a terminal!
1
2



