Code example for BigDecimal

Methods: multiplyprecisionscale

0
    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");
        res = a.round(mc).multiply(b.round(mc));
        assertEquals("incorrect value", "923456789012345670000000000000000", res.toString());
        res = res.round(mc);
        assertEquals("incorrect value", "9.2345678901234567E+32", res.toString());
        res = a.multiply(b, mc);
        assertEquals("incorrect value", "9.2345678901234576E+32", res.toString());
        assertEquals("Incorrect scale!", -16, res.scale());
        assertEquals("Incorrect precision!", 17, res.precision());
    } 
 
    public void testPowNonTrivial() { 
        BigDecimal a, b, res;
 
Connect your IDE to all the code out there  Get Codota for Java