title: Postgresql Numeric precision error on window function
body: <p>This is my query</p>
  <p><strong>Example 1</strong></p>
  <pre><code>SELECT sum(percent::numeric)::numeric
  FROM (
           SELECT (amount::numeric * 100::numeric) / sum(amount::numeric) OVER (PARTITION BY a, b, c)::numeric as percent
           FROM (
                    values ('a', 'b', 'c', 1, '609639'::numeric)
                         , ('a', 'b', 'c', 2, '72296.66'::numeric)
                         , ('a', 'b', 'c', 10, '174027.6'::numeric)
                         , ('a', 'b', 'c', 12, '154179.16'::numeric)
                         , ('a', 'b', 'c', 14, '97530.2'::numeric)
                         , ('a', 'b', 'c', 15, '1335529.7'::numeric)
                         , ('a', 'b', 'c', 25, '201315.1'::numeric)
                         , ('a', 'b', 'c', 51, '1424121.5'::numeric)
                         , ('a', 'b', 'c', 61, '51045.5'::numeric)
                         , ('a', 'b', 'c', 63, '14664.4'::numeric)
                         , ('a', 'b', 'c', 66, '740921.9'::numeric)
                         , ('a', 'b', 'c', 70, '189266.9'::numeric)
                ) AS sample_values (a, b, c, d, amount)
       ) as table_1;
  
  sum
  -------------------------
   99.99999999999999997676
  (1 row)
  
  </code></pre>
  <p><strong>Example 2</strong></p>
  <pre><code>SELECT sum(percent::numeric)::numeric
  FROM (
           SELECT (amount::numeric * 100::numeric) / sum(amount::numeric) OVER (PARTITION BY a, b, c)::numeric as percent
           FROM (
                    values  ('a', 'b', 'c', 2, '72296.66'::numeric)
                         , ('a', 'b', 'c', 10, '174027.6'::numeric)
                         , ('a', 'b', 'c', 12, '154179.16'::numeric)
                         , ('a', 'b', 'c', 15, '1335529.7'::numeric)
                         , ('a', 'b', 'c', 25, '201315.1'::numeric)
                         , ('a', 'b', 'c', 51, '1424121.5'::numeric)
                         , ('a', 'b', 'c', 61, '51045.5'::numeric)
                         , ('a', 'b', 'c', 63, '14664.4'::numeric)
                         , ('a', 'b', 'c', 66, '740921.9'::numeric)
                         , ('a', 'b', 'c', 70, '189266.9'::numeric)
                ) AS sample_values (a, b, c, d, amount)
       ) as table_1;
  
  sum
  -------------------------
   100.0000000000000000583
  (1 row)
  
  </code></pre>
  <p>I am casting everything to <code>numeric</code> and yet the query still gives me</p>
  <p><strong>Details</strong></p>
  <pre><code>psql --version
  psql (PostgreSQL) 13.1
  
  postgres=# select version();
  
                            version
  ------------------------------------------------------------
   PostgreSQL 13.1, compiled by Visual C++ build 1914, 64-bit
  (1 row)
  
  Windows 10 x64
  </code></pre>
  <p>I am expecting a clean <code>100</code> since numeric shouldn't have floating point error. What went wrong?</p>