0

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.

Vitalii
  • 7,565
  • 13
  • 53
  • 114
  • 6
    I think you may have misunderstood the recommendation: Use `BigDecimal` **or** do your calculation in cents (e.g., with an `int` or `long`). – T.J. Crowder Oct 19 '17 at 09:10
  • second one may make it complicated, but safer if **every** currency in your application is in cents and only the display (when you have one) uses whole dollars, then nothing bad can happen – Lino Oct 19 '17 at 09:10

1 Answers1

3

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

user207421
  • 289,834
  • 37
  • 266
  • 440