Java BigDecimal vs R vs Java Float, Double


I am working on a financial system where precision required is 6 decimal places only. We are currently using R but converting to Java. I had a debate with a colleague over whether we should go with BigDecimals or double / float primitive in Java. I was in favor of BigDecimal but his point was that R would be using primitives same as Java primitives so we would have already noticed if there were any issues with the precision. It should be noted that the end result we would convert to BigDecimal anyway this is just for the calculation itself. Who is correct here?

>Solution :

You should definitely use BigDecimal with DECIMAL 128. You should do this knowing that specifications may change in the future and more decimal points may be required. DECIMAL 128 is too too much solution, but it’s bullet proof.

Performance is important, but when it comes to money, accuracy is much much more important.

Leave a ReplyCancel reply