is there any particular reason you have to use BigDecimal in particular to work with these dollar-and-cent amounts? couldn't you just use integers and BigIntegers to work with whole numbers of cents instead? then you wouldn't need to round anything at all.
Firstly the way I'm running your code actually works fine and returns true
However if you want it to make it bullet-proof you could try the following
Hope this helps, Barry
Joined: Jan 07, 2005
Thanks. I should be calling setScale(2, BigDecimal.ROUND_HALF_UP) on each BigDecimal I use, then the compares work properly.
I guess I could have also used a long and moved the dollar amounts, including pennies, into them. However I would then need to convert double to long as well as strings. Since I have only a small number of computations, BigDecimal was the quickest approach.