>>> n=F.Fraction(3.56)
>>> n
Fraction(8016407336719483, 2251799813685248)
>>> n=F.Fraction('3.56')
>>> n
Fraction(89, 25)
Is it working as intended? Both results are correct, but the first one seems to be over the top. I stubmled it upon while solving this kata from codewars.
3.56
does not represent exactly one hundredth of 356. If you want exactly one hundredth of 356, you should use'3.56'
, to avoid floating-point rounding error. (Floating-point rounding error doesn't go away when you pass a float toFraction
.)