I am creating a BigDecimal from a double value of 0.495, and printing it to two decimal digits with HALF_UP
rounding mode. Here's the code:
BigDecimal d = new BigDecimal(0.495);
d = d.setScale(2, BigDecimal.ROUND_HALF_UP);
System.out.println(d.toPlainString());
I am expecting to see 0.50 as the result, but I am seeing 0.49 instead. ROUND_HALF_UP
should round up if the discarded fraction is >= .5.
So why am I seeing this behaviour?