Monday, July 15, 2013

BigNumber vs Double

Recently I worked on one project which involved using JAXB to generate XML message fro the excel file.   Some data in the file are financial amount and tax amount.  When it is read from the excel it is represented as the floating number.  However in the generated XML message these data occurs to have something like the below:


       <GSTAmount>26.789999999999999999999999999967899</GSTAmount>


In schema GSTAmount is defined as xsd:decimal and the rounding is done before marshaling by JAXB.  I did some serach using Google and learned some tips when dealing with financial amount in Java.


  1. Use BigDecimal rather than double when defining the financial amount.
  2. When using BigDecimal use its string conductor.
Here is the excellent link which explains this issue very clearly. How to Use Java BigDecimal: A Tutorial

1 comment:

  1. This comparison between BigNumber and Double is really informative! For developers working with containerized applications, Ninza Host can help you manage and test environments locally, ensuring smooth handling of numeric precision and performance across different data types.

    ReplyDelete