Code example for BigDecimal

Methods: precisionscalesubtract

0
        assertEquals("incorrect value", "2345678901234566.9", res.toString());
        assertEquals("Incorrect scale!", 1, res.scale());
        assertEquals("Incorrect precision!", 17, res.precision());
 
        mc = new MathContext(33, RoundingMode.UNNECESSARY);
        a = new BigDecimal("1234567890123456789012345678.9012395");
        b = new BigDecimal("1000000000000000090000000000.0000005");
        res = a.subtract(b, mc);
        assertEquals("incorrect value", "234567890123456699012345678.901239", res.toString());
        assertEquals("Incorrect scale!", 6, res.scale());
        assertEquals("Incorrect precision!", 33, res.precision());
    } 
 
    public void testMultiplyMathContextNonTrivial() { 
        MathContext mc;
        BigDecimal a, b, res;
 
        mc = new MathContext(17, RoundingMode.FLOOR);
        a = new BigDecimal("92345678901234567.8");
        b = new BigDecimal("10000000000000000.9");
Contextual code suggestions in your IDE  Get Codota for Java