title: Why doesn't this sum of percentages add up to 100%?
body: <p>I have a series of calculation times in a DB2 SQL DB that are stored as float with a default value of 0.0.</p>
  
  <p>The table being updated is as follows:</p>
  
  <pre><code>CREATE TABLE MY_CALC_DATA_TABLE
  (
      CALCDATE                 TIMESTAMP,
      INDIV_CALC_DURATION_IN_S FLOAT WITH DEFAULT 0.0,
      CALC_TIME_PERCENTAGE     FLOAT WITH DEFAULT 0.0
  )
  </code></pre>
  
  <p>Using a sproc. I am calculating the sum as follows:</p>
  
  <pre><code>CREATE OR REPLACE PROCEDURE MY_SCHEMA.MY_SPROC (IN P_DATE TIMESTAMP)
      LANGUAGE SQL
      NO EXTERNAL ACTION
  BEGIN
      DECLARE V_TOTAL_CALC_TIME_IN_S FLOAT DEFAULT 0.0;
  
      -- other stuff setting up and joining data
  
      -- Calculate the total time taken to perform the
      -- individual calculations
  
      SET V_TOTAL_CALC_TIME_IN_S =
          (
              SELECT
                  SUM(C.INDIV_CALC_DURATION_IN_S)
              FROM
                  MY_SCHEMA.MY_CALC_DATA_TABLE C
              WHERE
                  C.CALCDATE = P_DATE
          )
  
      -- Now calculate each individual calculation's percentage
      -- of the toal time.
  
      UPDATE
          MY_SCHEMA.MY_CALC_DATA_TABLE C
      SET
          C.CALC_TIME_PERCENTAGE =
              (C.INDIV_CALC_DURATION_IN_S / V_TOTAL_CALC_TIME_IN_S) * 100
      WHERE
          C.CALCDATE = P_DATE;
  
  END@
  </code></pre>
  
  <p>Trouble is, when I do a sum of all the CALC_TIME_PERCENTAGE values for the specified CALC_DATE it is always less than 100% with the sum being values like 80% or 70% for different CALC_DATES.</p>
  
  <p>We are talking between 35k and 55k calculations here with the maximum individual calculation's percentage of the total, as calculated above, being 11% and <em>lots</em> of calculations in the 0.00000N% range.</p>
  
  <p>To calculate the total percentage I am using the simple query:</p>
  
  <pre><code>SELECT
      SUM(C.CALC_TIME_PERCENTAGE)
  FROM
      MY_SCHEMA.MY_CALC_DATA_TABLE C
  WHERE
      C.CALCDATE = P_DATE;
  </code></pre>
  
  <p>Any suggestions?</p>
  
  <p><strong>Update:</strong> Rearranging the calc. as suggested fixed the problem. Thanks. BTW In DB2 FLOAT and DOUBLE are the same type. And now to read that suggested paper on floats.</p>