Code example for BigDecimal

Methods: scaleunscaledValue

        int precision = 46;
        RoundingMode rm = RoundingMode.CEILING;
        MathContext mc = new MathContext(precision, rm);
        String res = "1231212478987482988429808779810457634781384757";
        int resScale = -6;
        BigDecimal result = new BigDecimal(bA, mc);
        assertEquals("incorrect value", res, result.unscaledValue().toString());
        assertEquals("incorrect scale", resScale, result.scale());
        // Now test more than just RoundingMode.CEILING: 
        BigDecimal bd;
        BigInteger bi =  new BigInteger( "12345678901234567890123456789012345");
        BigInteger nbi = new BigInteger("-12345678901234567890123456789012345");
        mc = new MathContext(31, RoundingMode.UP);
        bd = new BigDecimal(bi, mc);
        assertEquals("incorrect value",  "1.234567890123456789012345678902E+34", bd.toString());
        bd = new BigDecimal(nbi, mc);
        assertEquals("incorrect value", "-1.234567890123456789012345678902E+34", bd.toString());
Connect your IDE to all the code out there  Get Codota for Java