Skip to content

Support for string and decimal fractions

Choose a tag to compare

@bradley101 bradley101 released this 16 Oct 17:04
1f266d9

Now you can initialise a Fraction object using strings and decimals.

f1 = Fraction('1/3')
f2 = Fraction('1/2', '1/4')
f3 = Fraction(0.5, 0.25)
f4 = Fraction('0.5', '1/4')

All the combinations of strings, decimals and fractional strings are valid on both numerator and denominator.

Also now you can convert a Fraction object into a float string

>>> Fraction('2/3').todecimal(decplaces=4)
0.6666