I was working on question 33 of Project Euler in Python when I noticed something I do not understand.
The answer to the question needed the denominator given in its lowest common terms. So I thought I would use the float.as_integer_ratio()
to check what the denominator was. It turns out that 0.01.as_integer_ratio()
returns (5764607523034235, 576460752303423488)
and 0.1.as_integer_ratio()
returns (3602879701896397, 36028797018963968)
instead of the expected 1/100
and 1/10
.
Why does it behave like this? I am guessing it has something to do with how these numbers are stored on the computer. I have also tried the Fractions library from Python but this gives the same results. I hope someone can explain why it behaves like this to me.