title: Exact decimal division in MySQL
body: <p>How to properly divide two <code>DECIMAL</code> values in MySQL and get a result accurate to the number of digits defined in the column type?</p>
  
  <p>Example:</p>
  
  <pre><code>select cast(1/2 as decimal(4,4)),
  cast(1 as decimal(4,4))/2,
  cast(1 as decimal(4,4))/cast(2 as decimal(4,4));
  </code></pre>
  
  <p>Results:</p>
  
  <pre><code>'0.5000', '0.49995000', '1.00000000'
  </code></pre>
  
  <p>Why is the second result innacurate? Why is the third result not '0.5000'?</p>
  
  <p>Note: I can't just use the first form, I need to perform calculations with columns stored as decimals.</p>