Skip to content Skip to sidebar Skip to footer

Android Development - Sqlite Storing Float

When I store float value widt SQLiteDatabase.insert the stored value will be different than the original, see below: I have a database width: db.execSQL('CREATE TABLE IF NOT EXISTS

Solution 1:

Never thought this thread will help anybody else, but allas here it goes.

Basically your problem is that you use float for the type in the java code. Float is with very low precision. Read the thread I link to, together with all comments and the linked chat. If you still have any problems write back.

You probably know that the double values are stored only upto certain precision in the computers. Even though the values look weird in the database, this is the best approximation of your values you can get when using float. With double you can increase the precision, but you will never get to perfect state. Maybe if you insist on getting precise values limiting the real size in the database might be a way to go.

EDIT As I could not make you believe it IS a precision problem I include the following program:

float f = 22.2;
printf("The number is: %.9f\n", f);

The output is:

22.200000763

I suggest you try it. As you can see this is exactly the number you point out.

Post a Comment for "Android Development - Sqlite Storing Float"