Search code examples
javacurrencybigdecimal

Java: BigDecimal for money and working with cents


I need to do some fee calculator. One suggested me two things:

  • use BigDecimal as data types.
  • make all calculations in cents (I make my calculation not for a 15.99$ but for 1599 cents)

I agree with first one, but do I really need to calculate everything in cents? This will add some conversion operations and make code more complicated.


Solution

  • These are alternatives. You should use BigDecimal, in dollars.