I have a BigDecimal
like this
var a = new BigDecimal("1234.56")
and I want to round it to commercially to two places before the decimal, so that I get something equivalent to
var b = new BigDecimal("1200.00")
so that
(new BigDecimal("1200.00")).equals(b)
.
My best approach currently is
var b = new BigDecimal(a.setScale(-2, RoundingMode.HALF_UP).toPlainString()).setScale(2);
but I'm unsure if this is the right way because compared to positive scales it seems rather verbose. Is this the best way to do it?