JAXB, BigDecimal or double?
Posted
by Alex
on Stack Overflow
See other posts from Stack Overflow
or by Alex
Published on 2010-05-10T11:35:50Z
Indexed on
2010/05/10
11:44 UTC
Read the original article
Hit count: 502
I working on different web-services, and I always use WSDL First.
JAXB generates for a Type like:
<xsd:simpleType name="CurrencyFormatTyp">
<xsd:restriction base="xsd:decimal">
<xsd:totalDigits value="13"/>
<xsd:fractionDigits value="2"/>
<xsd:minInclusive value="0.01"/>
</xsd:restriction>
</xsd:simpleType>
a Java binding type BigDecimal
(as it's mentioned in JAXB specification).
When I then do some simple arithmetic operation with values of the type double
(which are stored in a database and mapped via hibernate to the type double) I run into trouble.
<ns5:charge>0.200000000000000011102230246251565404236316680908203125</ns5:charge>
<ns5:addcharge>0.0360000000000000042188474935755948536098003387451171875</ns5:addcharge>
<ns5:tax>0.047199999999999998900879205621095024980604648590087890625</ns5:tax>
<ns5:totalextax>0.2360000000000000153210777398271602578461170196533203125</ns5:totalextax>
What would be the right way?
- Convert all my values into double (JAXB binding from
BigDecimal
todouble
) - Hibernate mapping
double
toBigdecimal
and do all my arithmetic operations in one object type.
© Stack Overflow or respective owner