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".

Usually, the "double" type should *never* be used for precise values, such as currency. If you have such requirement, the DECIMAL type would be a better choice.

Please note that this is not only valid for Derby: Most computer languages (such as Java) exhibit the same behavior. In Java, for example, if you need exact values, you will use the BigDecimal type. Not "double".
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html

Hope this helps,
Sylvain

--
Website: http://www.chicoree.fr


Reply via email to