0

the property is defined with "addFloatProperty" in the model generator. When i store a float for example "5.23" the database show me afterwards "5.23000001907349". I would expect that 5.23 is stored. By inserting it manually everything is fine.

How to fix it?

drindt
  • 901
  • 10
  • 15

1 Answers1

0

The greenDao 'float' property is stored in the DB as a REAL - so you're going to have all the expected precision issues associated with floating point numbers.

REAL. The value is a floating point value, stored as an 8-byte IEEE floating point number. [SQLite Docs]

DDD
  • 1,462
  • 15
  • 19
  • As i already mentioned, when i do a manual insert in the table with the sqlite3 shell it works as expected. The database contains after the insert into the correct 5.23 instead of 5.23000001907349. So i don't know why here is a reinterpretation. – drindt Mar 26 '14 at 13:19
  • Read the section "2.0 Type Affinity" - SQLite can store your value in a variety of ways, even as Text in some cases. greenDao will be inserting the values via SQLiteStatement.bind methods (bindDouble in this case). I expect your shell query will be using some form of text parsing. All of this should be irrelevant to you however, as once back in your Java code the greenDao entity will give you back the same float. If you're dealing with currencies then you shouldn't be using floating points. – DDD Mar 26 '14 at 17:02
  • Ok, i switched to StringProperty and have done some tests. With String the problem is gone. Just the annoyance of the conversion between the datatypes. Thank you for your help! – drindt Mar 26 '14 at 21:38