title: Query with SUM of decimal values returns with unexpected value
body: <p>I'm developing an application which uses a SQLite in-memory database and the anomaly is the following:</p>
  <p>Used query:</p>
  <pre class="lang-sql prettyprint-override"><code>SELECT FE1 
  FROM DRC 
  WHERE DTS &gt;= '2021-04-21T17:04:44+02:00' 
  AND DTS &lt; '2021-04-21T17:20:09+02:00' 
  AND (DTS IN (SELECT DTS FROM NYN WHERE CNC = '0')
    OR DTS IN (SELECT DTS FROM ESN WHERE CNC = '0')
    OR DTS IN (SELECT DTS FROM SZN WHERE CNC = '0')
    OR DTS IN (SELECT DTS FROM VBN WHERE CNC = '0') 
  )
  </code></pre>
  <p>It returns with:</p>
  <pre class="lang-none prettyprint-override"><code>999999,99
  999999,99
  999999,99
  999999,99
  999999,99
  999999,99
  999999,99
  999999,99
  999999,99
  999999,99
  0,09
  -999999,99
  -999999,99
  -999999,99
  -999999,99
  -999999,99
  -999999,99
  -999999,99
  -999999,99
  -999999,99
  -999999,99
  -0,09
  </code></pre>
  <p>The type of FE3 is Text, therefore all calculation should be cast to Decimal (with correction of decimal separator from comma to dot).</p>
  <p>The expected sum of these values must be 0 after conversion.</p>
  <p>But if I run the query:</p>
  <pre class="lang-sql prettyprint-override"><code>SELECT SUM(CAST(REPLACE(FE1,',','.') AS DECIMAL))
  FROM DRC
  WHERE DTS &gt;= '2021-04-21T17:04:44+02:00' 
  AND DTS &lt; '2021-04-21T17:20:09+02:00' 
  AND (DTS IN (SELECT DTS FROM NYN WHERE CNC = '0')
    OR DTS IN (SELECT DTS FROM ESN WHERE CNC = '0')
    OR DTS IN (SELECT DTS FROM SZN WHERE CNC = '0')
    OR DTS IN (SELECT DTS FROM VBN WHERE CNC = '0')
  )
  </code></pre>
  <p>The result is <strong>-1.31316482687716e-09</strong> even if it should be <strong>0</strong></p>
  <p>If I run the same query in SQL Server, I get the proper 0 value.</p>
  <p>What can be the problem?</p>