On 7 Feb 2015, at 5:57am, Abdul Aziz <abduldblog...@gmail.com> wrote:

> *again I converted back to float this string formatted value, and printed
> into Log, I was clearly seeing values upto 6 decimal places , but after
> insertion into sqlite db, when after generation of sqlite db file, was
> getting values upto 11-12 decimal places!*

SQLite itself would have converted your text (to six digits) and stored the 
resulting number. When you asked to retrieve your value, SQLite would have 
retrieved that number -- still at six digits.

However if you ask for the retrieved figure as a number (as opposed to a 
string) the programming language you use has to put the resulting number into a 
'float' variable.  And in doing this it would have to turn the number back into 
float format, which would introduce the extra 'garbage' digits.  So yes, you 
can argue that there is a bug somewhere, but if there is one it's in the 
Android interface to SQLite, not in SQLite itself.

You can avoid this by asking for the retrieved figure as a string, not a 
number.  Or by storing the value as a TEXT column instead of a REAL column, 
which is the solution you came up with.  So I'm glad you found a solution.

It might be worth asking yourself why you are trimming your values to six 
digits and then saving the result as a number.  It would make more sense to 
trim your values and then handle the number as a string from then onwards.  Or 
to handle all the digits you have and to convert to text as six digits just 
before you put the number on the display.  Both of these would be more 
mathematically 'correct' than what you are doing.

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

Reply via email to