I try to represent a floating point number as a ratio of two integers, but for some reason the integers that I get are quite different from what I would expect to see. Can somebody explain this?
>>> value = 3.2
>>> ratios = value.as_integer_ratio()
>>> ratios
(3602879701896397, 1125899906842624)
>>> ratios[0] / ratios[1]
3.2
I would say that (32, 10)
or (16, 5)
are much better solutions to the problem. What's strange is that if I try to do the same for number like 2.5, the answer is exactly what I would expect
>>> value = 2.5
>>> value.as_integer_ratio()
(5, 2)