title: Float to Fraction conversion in Python
body: <p>While doing exercise on the topic of float type to Fraction type conversion in Python 3.52, I found the difference between the two different ways of conversion.</p>
  
  <p>The first method is:</p>
  
  <pre><code>&gt;&gt;&gt; from fractions import Fraction
  &gt;&gt;&gt; x = 1232.23
  &gt;&gt;&gt; f = Fraction(*x.as_integer_ratio())
  &gt;&gt;&gt; print(f)
  2709702426188841/2199023255552      #Answer
  </code></pre>
  
  <p>The second method is:</p>
  
  <pre><code>&gt;&gt;&gt; from fractions import Fraction
  &gt;&gt;&gt; x = 1232.23
  &gt;&gt;&gt; f = Fraction(str(x))
  &gt;&gt;&gt; print(f)
  123223/100                          #Answer
  </code></pre>
  
  <p>I want to know the reason behind these two different answers? Sorry if this is a stupid question , I am new to programming and Python.</p>
  
  <p>Edited: I found a way to convert inaccurate fraction obtained by first method to accurate by <code>limit_denominator</code> method:</p>
  
  <pre><code>&gt;&gt;&gt; from fractions import Fraction
  &gt;&gt;&gt; x = 1232.23
  &gt;&gt;&gt; f = Fraction(*x.as_integer_ratio())
  &gt;&gt;&gt; f = f.limit_denominator(100)     
  &gt;&gt;&gt; print(f)
  123223/100
  </code></pre>