BigDecimal
all the way. I've heard of some folks creating their own Cash
or Money
classes which encapsulate a cash value with the currency, but under the skin it's still a BigDecimal
, probably with BigDecimal.ROUND_HALF_EVEN
rounding.
Edit: As Don mentions in his answer, there are open sourced projects like timeandmoney, and whilst I applaud them for trying to prevent developers from having to reinvent the wheel, I just don't have enough confidence in a pre-alpha library to use it in a production environment. Besides, if you dig around under the hood, you'll see they use BigDecimal
too.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…