Code example for BigDecimal

Methods: scaleunscaledValue

        int precision = 5;
        RoundingMode rm = RoundingMode.CEILING;
        MathContext mc = new MathContext(precision, rm);
        String res = "-23876";
        int resScale = -224;
        BigDecimal result = new BigDecimal(a, mc);
        assertEquals("incorrect value", res, result.unscaledValue().toString());
        assertEquals("incorrect scale", resScale, result.scale());
        // Now test more than just RoundingMode.CEILING: 
        String biStr = new String( "12345678901234567890123456789012345.0E+10");
        String nbiStr = new String("-12345678901234567890123456789012345.E+10");
        BigDecimal bd;
        mc = new MathContext(31, RoundingMode.UP);
        bd = new BigDecimal(biStr, mc);
        assertEquals("incorrect value",  "1.234567890123456789012345678902E+44", bd.toString());
        bd = new BigDecimal(nbiStr, mc);
        assertEquals("incorrect value", "-1.234567890123456789012345678902E+44", bd.toString());
Connect your IDE to all the code out there  Get Codota for Java