I hope you know what you're doing with trying to preserve that much 
significance.  Ths first time you stick it in a double or long double variable 
you'll lose it.  You can use the HPAlib to get 32 digits 
http://www.nongnu.org/hpalib/


// Example showing digit loss -- doesn't matter double or long double -- at 
least under GCC 4.1.2
#include <stdio.h>
int main()
{
        double d1=123456789123456789.123456;
        long double d2=123456789123456789.123456;
        printf("%f\n%Lf\n",d1,d2);
        return 0;
}
123456789123456784.000000
123456789123456784.000000

But since you don't seem to understand the limits of floating point values I'm 
worried you're heading down a failing path.

But if what you want to do will really work just make the field text and then 
do whatever you're doing that preserves the significant digits.  It's a common 
misconception that significant digits is to the right of the decimal point but 
that's not true.  It means ALL the digits.

sqlite> CREATE TABLE tab1 (
   ...>   a INTEGER,
   ...>   c DECIMAL(30,7),
   ...> d TEXT);
insert into tab1 
values(1,123456789123456789.123456,'123456789123456789.123456');
1|123456789123456784|123456789123456789.123456


Michael D. Black
Senior Scientist
NG Information Systems
Advanced Analytics Directorate



________________________________________
From: sqlite-users-boun...@sqlite.org [sqlite-users-boun...@sqlite.org] on 
behalf of LacaK [la...@zoznam.sk]
Sent: Tuesday, March 22, 2011 1:51 AM
To: sqlite-users@sqlite.org
Subject: EXT :[sqlite] storing big numbers into NUMERIC, DECIMAL columns

Hi,
I have table like this:
CREATE TABLE tab1 (
  a INTEGER,
  c DECIMAL(30,7),
  ...
);

When I am trying insert values like:
INSERT INTO tab1 (a,c) VALUES(1, 123456789123456789.123456);
INSERT INTO tab1 (a,c) VALUES(2, '123456789123456789.123456');

values for c column are always rounded or cast to :
1.23456789012346e+19

If I understand correctly column c has NUMERIC affinity, but when
storing values, they are stored using REAL storage class.
But why, when conversion from TEXT is NOT lossless ? (AFAIU first 15
significant digits are not preserved)
Is there way how to store numeric values, which are out of REAL range ?

TIA
-Laco.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to