I've external data read in to my java program and there is a value for example 23.4 which I create a BigDecimal value of how ever further up in the program when doing comparison it will fails because 23.4 and 23.40 aren't the same.
What is the best way to have this fixed? Should I add a 0 to 23.4 so its new value will become 23.40 ? or should I use the compareTo() method to ignore 0 ? Are there any other solutions?
I think that's the best solution - check if bigDecimalA.compareTo(bigDecimalB) == 0, if true that means they're equal. There are other things you could do, like check if check if bigDecimalA.doubleValue() == bigDecimalB.doubleValue(). That will give you the right answer as long as your numbers don't use too many digits. But the first one seems more reliable.