math converting to and from floats belowto convert fraction to floating point numberuse floatlike float(fraction( ) on the other handsay we want to convert to fraction unfortunatelywe should not do fraction becauseas mentionedsome numbersincluding are not represented exactly on the computer in factfraction returns the following fraction objectfraction( insteaduse string notationlike belowfraction 'limiting the denominator one useful method is limit_denominator for given fraction objectlimit_denominator(xfinds the closest fraction to that value whose denominator does not exceed here is some examplesfraction 'limit_denominator( fraction 'limit_denominator( fraction' 'limit_denominator( fraction( fraction( fraction( the last example returns pretty close fractional approximation to it is off by less than greatest common divisor the fractions module contains useful function called gcd that returns the greatest common divisor of two numbers here is an examplefrom fractions import gcd print'the largest factor and have in common is 'gcd( )the largest factor and have in common is the decimal module python has module called decimal for doing exact calculations with decimal numbers as we've noted few times nowsome numberssuch as cannot be represented exactly as float here is