Code example for BigDecimal

Methods: abs, scale

0
    /** 
     * Abs(MathContext) of a negative BigDecimal 
     */ 
    public void testAbsMathContextNeg() { 
        String a = "-123809648392384754573567356745735.63567890295784902768787678287E+21";
        BigDecimal aNumber = new BigDecimal(a);
        int precision = 15;
        RoundingMode rm = RoundingMode.HALF_DOWN;
        MathContext mc = new MathContext(precision, rm);
        String result = "1.23809648392385E+53";
        int resScale = -39;
        BigDecimal res = aNumber.abs(mc);
        assertEquals("incorrect value", result, res.toString());
        assertEquals("incorrect scale", resScale, res.scale());
    } 
 
    /** 
     * Abs(MathContext) of a positive BigDecimal 
     */ 
    public void testAbsMathContextPos() { 
        String a = "123809648392384754573567356745735.63567890295784902768787678287E+21";