I am Seeing some strange behavior from BigDecimal When I do division using mathContext the output is different than when I do the division by directly providing the scale and rounding mode Here is an example that I think should provide the same output
public static void main(String...args){
MathContext mc = new MathContext(3,RoundingMode.HALF_UP);
BigDecimal four = new BigDecimal(4);
BigDecimal three = new BigDecimal(3);
System.out.println(four.divide(three,3,RoundingMode.HALF_UP));
System.out.println(four.divide(three,mc));
}
Output:
1.333
1.33
It appears that the scale is treated differently when using MathContext. Or I dont understand when to use which.