Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can SQLite not add up DECIMAL values?

Tags:

sqlite

    sqlite> create table test (Qty DECIMAL(10,2));
    sqlite> insert into test values(1059.79);
    sqlite> insert into test values(-1050);
    sqlite> insert into test values(83.58);
    sqlite> insert into test values(130.51);
    sqlite> insert into test values(-5);
    sqlite> insert into test values(-136.68);
    sqlite> insert into test values(-2.6);
    sqlite> insert into test values(-75);
    sqlite> insert into test values(-4.6);
    sqlite> select sum(Qty) FROM TEST;
    -6.21724893790088e-14

Given that I explicitly specified DECIMAL(10,2) as the field type, why is the sum not 0?

like image 986
Nikki Locke Avatar asked Oct 24 '25 21:10

Nikki Locke


1 Answers

SQLite does not have a DECIMAL type. Math is performed using 64-bit floating point values.

See SQLite3 data types

like image 168
Colonel Thirty Two Avatar answered Oct 27 '25 23:10

Colonel Thirty Two



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!