Code example for BigDecimal

Methods: scale, unscaledValue

0
        int precision = 5;
        RoundingMode rm = RoundingMode.CEILING;
        MathContext mc = new MathContext(precision, rm);
        String res = "45766";
        int resScale = -14;
        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 
        // 
        BigDecimal bd;
 
        mc = new MathContext(15, RoundingMode.UP);
        bd = new BigDecimal(78901234567890125L, mc);
        assertEquals("incorrect value",  "7.89012345678902E+16", bd.toString());
        bd = new BigDecimal(-78901234567890125L, mc);
        assertEquals("incorrect value", "-7.89012345678902E+16", bd.toString());
 
        mc = new MathContext(12, RoundingMode.DOWN);
        bd = new BigDecimal(78901234567890125L, mc);