title: Python - safe conversion of quotient of floats to int
body: <p>In my situation I am attempting to divide one float <code>p</code> by another <code>q</code>. The top is a multiple of the bottom and both have these properties:</p>
  
  <ol>
  <li>Exactly representable in decimal</li>
  <li>Have at most 3 or 4 significant figures</li>
  <li>Are between <code>1</code> and <code>1e-8</code>.</li>
  </ol>
  
  <p>(think, e.g., <code>p=.0014</code> and <code>q=.00002</code>)</p>
  
  <p>In a perfect world the division would come out to a perfect integer (here 70). But floating point arithmetic is <a href="https://stackoverflow.com/questions/10011302/python-numpy-arange-unexpected-results">often imperfect</a>.</p>
  
  <p>I would like the simplest, safest, and most efficient method to avoid an error of returning <code>p/q - 1</code> when I cast the quotient to <code>int</code>. </p>
  
  <p>My best solution right now is to do something like this:</p>
  
  <pre><code>int(p/q + 1e-10)
  </code></pre>
  
  <p>but that feels unclean and potentially less efficient that what may be possible.</p>
  
  <p>Also, I am aware I can round, but that seems misleading in the code and potentially less efficient than a straight cast of some sort.</p>