Title: Why my Sum result in SQLite is wrong?
Tags: sqlite
Question: Why my following SQL query
Insert Into Test (ItemQty) VALUES (1.445);
Insert Into Test (ItemQty) VALUES (0.000000000000001);
Select Sum(ItemQty) from Test;
produces 1.445 as result and not 1.445000000000001 ?
What am i missing here?
Comment: https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

Comment: You need to understand more about how computers and databases represent numbers.  First, understand the type of `ItemQty` and then do research on fixed- or floating- point values.

Here is the accepted answer: SQLite Version 3 REAL values are stored as '8-byte IEEE floating point numbers' (see https://www.sqlite.org/datatype3.html). These values allow for just less than 16 decimal digits (see https://en.wikipedia.org/wiki/IEEE_floating_point#Basic_and_interchange_formats). However, the length of the constant 1.445000000000001 is 17, which is (just) beyond the capability of this format.
In fact, when I recreated your example but instead inserted the second value with one less zero after the decimal point I received the result 1.44500000000001.
Because that's only 16 digits long.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:12/15/16', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<sqlite>', 'Title': 'Why my Sum result in SQLite is wrong?', 'ViewCount': 153, 'id': 41163626, 'user_AboutMe': '', 'user_AccountId': 23621.0, 'user_DisplayName': 'OrElse', 'user_Reputation': 9281.0, 'user_Views': 1506.0, 'user_id': 59314.0}}