views:

104

answers:

2

For more info, see my other question, here. So anyway, I'm using BigDecimals to represent currency in my application (it deducts a markdown percentage and adds sales tax), but it seems that If I use a BigDecimal for the price, everything needs to be BigDecimals. Is it OK to use a BigDecimal for the markdown percentage field (instead of a float), and also for the PST and GST constants (sales tax, 0.08 & 0.05)? Oh and also, do you think I should store the markdown field in percentage or decimal? Either way, I would have to convert it to the other for display, since I show p / 100 = d. And subtotal means the total cost before tax, right?

Thanks!!

+1  A: 

Yes its fine - unless you have a specific problem - memory usage or something - stick with BigDecimals.

You might find the NumberFormat useful for formatting.

Corehpf
Yes I am using that, check my other question I posted to see the 24 comments on an answer where I figured out what way to format and display and store them :-).
Mk12
+3  A: 

Different industries will have different standards for this. In finance, for example, it's common to do calculations to 5 or even 8 decimal places even if you're only display 2 or 3.

BigDecimals are preferred for being completely accurate for multiplication, addition and subtraction (division isn't normally an issue when it comes to currency amounts).

cletus