Reputation: 3
How to properly save a numeric values into SQLite3. I've used Real type for storing numeric value. For example: when I store 233333.00 is fine. But when i store 23333333.00 it becomes 23333300.00. Why is it saved as 2.3333333E7 and retrieved as 2.33333e+07. Is there a way to overcome this?
Upvotes: 0
Views: 456
Reputation: 146281
You are losing precision because your program's variable has single precision and you need double.
Floating point is actually perfectly accurate for integral values that fit in the mantissa.
You get 24 bits fot singles and 53 for double.
This isn't an sqlite issue at all.
Upvotes: 0
Reputation: 17587
The real type used by SQLite is stored as 8-byte IEEE floating point number and can't store all values exactly. If you want exact vales, use either string of integer.
Upvotes: 2