Code example for BigDecimal

Methods: add, precision, scale

0
                a.round(mc).add(b.round(mc)).toString());
        res = a.add(b, mc);
        assertEquals("incorrect value", "223456789012345.68", res.toString());
 
        mc = new MathContext(33, RoundingMode.UNNECESSARY);
        a = new BigDecimal("1234567890123456789012345678.9012395");
        b = new BigDecimal("1000000000000000090000000000.0000005");
        res = a.add(b, mc);
        assertEquals("Incorrect value!", "2234567890123456879012345678.90124", res.toString());
        assertEquals("Incorrect scale!", 5, res.scale());
        assertEquals("Incorrect precision!", 33, res.precision());
    } 
 
    public void testSubtractMathContextNonTrivial() { 
        MathContext mc;
        BigDecimal a, b, res;
 
        mc = new MathContext(17, RoundingMode.FLOOR);
        a = new BigDecimal("12345678901234567.8");
        b = new BigDecimal("10000000000000000.9");
        assertEquals("incorrect value", "2345678901234567",