Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Long decimal numbers in SQLite

Tags:

sql

sqlite

Required to store in a SQLite database the long decimal numbers. 12 signs - integer part, and 8 - in decimal, like that - '123456789012,12345678' (positive numbers only)

drop table if exists table1;

CREATE TABLE table1 (
 a INTEGER,
 b DECIMAL(20,8)
); 

INSERT INTO table1 select 1, 123456789012.12345678;

select * from table1;

Query result:

RecNo a                     b 
----- - --------------------- 
    1 1 123456789012.12345900 

As we can see, it is rounding off the last digits in the decimal part. How can I get accurate result without rounding?

like image 415
HeathRow Avatar asked Nov 15 '25 11:11

HeathRow


1 Answers

SQLite stores numeric (decimal) data types up to 8 bytes. But that is not sufficient to store your number including decimal places.

You could use blob to store it or text.

like image 182
juergen d Avatar answered Nov 17 '25 08:11

juergen d



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!