Better than the BigDecimal type for pricing in Java?

I need a financial type that will always contain numbers in the format X ... X.YY, even 20 digits, so I will get rid of rounding, formatting and other headaches. There is one?

Added: In other words, I'm looking for something like:

Financial f = 1000.24;

f.setCurrency (USA);

System.out.print (f.toString ()); → $ 1'000.24

+3
source share
2 answers

You can always keep financial data in debt, expressed in pennies. But, as you say, various headaches are involved in this, and the maximum value, I think, is 19 digits. So BigDecimal seems to be the way to go.

(, BitInteger/BigDecimal, , , .)

+4

Java.

BigInteger ( ), , . ( ). , BigInteger , .

0

All Articles