title: SQL Server rounding Error, Giving different values
body: <p>I have a Stored Procedure that does a lots of calculation, stores the results in several temporary table.
  Finally calculating the sum  and rounding to two decimal and stores in a temporary table and selects that.</p>
  
  <p>All the intermediate and final temporary table has datatype float for the column of concern.</p>
  
  <p><strong>original Scenario:</strong></p>
  
  <pre><code>Declare @Intermediate table
  {
   --several other columns
  
  Labor float
  
  --several other columns
  };
  
  ---Lots of calculation ---xx-----
  
  Declare @Final table
  {
   --several other columns
  
  LaborTotal float
  
  --several other columns
  };
  
  INSERT INTO @Final  SELECT ROUND(ISNULL((SELECT SUM([Labor]) FROM @Intermediate ),0),2)  AS LaborTotal;
  
  SELECT * FROM @Final;
  
  Result: 7585.22  --&gt; when rounded  //Here is the error Expecting 7585.23
          7585.225 --&gt; when not rounded
  </code></pre>
  
  <p><strong>TestCases :</strong></p>
  
  <pre><code>   DECLARE @test float = 7585.225;
     SELECT ROUND(@test,2) AS Result; --&gt; results 7585.23
  
     SELECT ROUND(7585.225,2) AS Result --&gt; results 7585.23
  </code></pre>
  
  <p>Inserted individual values to a temporary table, and then calculated the sum</p>
  
  <pre><code>DECLARE @TmpTable table
  (
   MaterialAmount float
   ,LaborAmount float
  );
  
  INSERT INTO @TmpTable VALUES (12.10,1218.75);
  INSERT INTO @TmpTable VALUES (12.10,1090.125);
  INSERT INTO @TmpTable VALUES (12.10,900);
  INSERT INTO @TmpTable VALUES (12.10,1632.6);
  INSERT INTO @TmpTable VALUES (12.10,1625);
  INSERT INTO @TmpTable VALUES (12.10,1118.75);
  
  
  SELECT ROUND(ISNULL((SELECT SUM(MaterialAmount) FROM @TmpTable), 0),2) AS MatSum,
         ISNULL((SELECT SUM(LaborAmount) FROM @TmpTable), 0) AS LabSumUnrounded, --&gt; 7585.225
         ROUND(ISNULL((SELECT SUM(LaborAmount) FROM @TmpTable), 0),2) AS LabSum;  --&gt; 7585.23
  
  SELECT ROUND(SUM(MaterialAmount),2),
         ROUND(SUM(LaborAmount),2)   ---&gt; 7585.23
     FROM @TmpTable;
  </code></pre>
  
  <p>Any idea/suggestion why i am getting 0.01 difference in my original scenario, while getting exact values in all my testcases ?
  Thanks in advance.</p>