Sylvain Leroux wrote:
sarah.kho a écrit :

Hi
I have some double field in my tables and when I looked into the database
using sql client I saw that values that I inserted into the database are
changed. for example:

2.30 is stored as 2.299999952316284
1.7 is stored as 1.7000000476837158

I am using JPA, the property type in JPA entities are float and my JPA
provider is toplink essential.

Is it normal or something is wrong with my database or JPA entities?

Thanks.


"Double" values are stored as binary numbers. Since a decimal value cannot usually be expressed in such form, you only have an approximation of the value. Thats' how 2.30 became 2.299999952316284. This difference is called the "roundoff error".
In this particular case the original double value is also being cast to 'float' at some point and thus losing about 7 extra digits of accuracy.

Mark Thornton

Reply via email to