title: SQL floating-point precision limited to 6 digits
body: <p>I have the following set of calculations in excel that I want to be able to use in a stored procedure.</p>
  
  <p>Excel</p>
  
  <pre><code>CellA: 45/448.2 = 0.100401606425703
  CellB: 1-CellA = 0.899598393574297
  CellC: 1-CellB = 0.100401606425703
  CellD: CellC * 448.2 = 45.000000000000000
  </code></pre>
  
  <p>In SQL I am doing the following:</p>
  
  <pre><code>declare @a decimal(18,15) = 45/448.2  
  declare @b decimal(18,15) = 1-@a
  declare @c decimal(18,15) = 1-@b
  declare @d decimal(18,15) = @c * 448.2
  </code></pre>
  
  <p>I have also tried running the calculation in one line</p>
  
  <pre><code>declare @e decimal(18,15) = (1-(1-(45/448.2)))*448.2
  </code></pre>
  
  <p>when I return the values SQL gives me the following:</p>
  
  <pre><code>@a: 0.100401000000000
  @b: 0.899599000000000
  @c: 0.100401000000000
  @d: 44.999728200000000
  
  @e: 44.999728200000000
  </code></pre>
  
  <p>I've tried adjusting the precision of the decimals in SQL but I nothing makes a difference, it only returns the first 6 digits of the decimal.</p>
  
  <p>Does Excel do any optimization when running the formula?</p>
  
  <p>Any ideas?</p>