'Closest Rational to self with denominator at most max_denominator.
>>> from sympy import Rational
>>> Rational(\'3.141592653589793\').limit_denominator(10)
22/7
>>> Rational(\'3.141592653589793\').limit_denominator(100)
311/99'

def limit_denominator(self, max_denominator=1000000):

    f = fractions.Fraction(self.p, self.q)
    return Rational(f.limit_denominator(fractions.Fraction(int(max_denominator))))
