Hi all

I am having a problem accumulating decimal values.

I am actually using Python, but I can reproduce it in the sqlite3 interactive 
terminal.

SQLite version 3.8.6 2014-08-15 11:46:33
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.

sqlite> CREATE TABLE fmtemp (acno INT, balance DECIMAL);
sqlite> INSERT INTO fmtemp VALUES (1, 0);

sqlite> UPDATE fmtemp SET balance = balance + 123.45;
sqlite> SELECT bal FROM fmtemp;
123.45

sqlite> UPDATE fmtemp SET balance = balance + 123.45;
sqlite> SELECT balance FROM fmtemp;
246.9

I repeat this a number of times, and it runs fine, until this happens -

sqlite> UPDATE fmtemp SET balance = balance + 123.45;
sqlite> SELECT bal FROM fmtemp;
5802.15

sqlite> UPDATE fmtemp SET balance = balance + 123.45;
sqlite> SELECT bal FROM fmtemp;
5925.59999999999

sqlite> UPDATE fmtemp SET balance = balance + 123.45;
sqlite> SELECT bal FROM fmtemp;
6049.04999999999

Can anyone explain what is going on, and is there a way to avoid it?

Thanks

Frank Millman

Reply via email to