On 19 Dec 2011, at 4:38pm, Alexandre K wrote:

> I have a question about C binding for sqlite. I have seen those for
> integer, float... but I was wondering how to deal with a NUMERIC (x, y)
> type ?
> We can't use float or double, we could loose precision, so maybe with a
> string ?

There are two standard ways to deal with fixed-precision numbers in SQLite: 
bind them as integers or as strings.

Storing as integers is useful if you see them as numbers you might want to do 
maths on them.  For a column of prices in Euros, for example, you would 
multiply all your numbers by a hundred, then store those as integers.  So a 
value of 1 would mean one cent, and a value of 100 would mean one euro.  Doing 
this means you can do things like sum(price) on a column and SQLite could do 
the calculations quickly and with full precision.  Your program (or a library 
it uses) must know to multiply or divide by 100 when it stores or retrieves a 
value from that column.

Storing as strings is useful if you are storing numbers you expect will 
probably be used only for printing.  This saves time doing conversion, and it 
means you definitely know where the decimal point went.  It also means that 
length(price) is faster, which will also speed up printing.

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

Reply via email to