Code example for BigDecimal

Methods: movePointRight, scale, scaleByPowerOfTen, toString

0
        } catch (ArithmeticException expected) {
        } 
    } 
 
    public void testScaleByPowerOfTenEx() { 
        BigDecimal a = new BigDecimal("12345.6789012345678901234567890123456789");
        BigDecimal res = a.movePointRight(10);
        assertEquals("incorrect scale", 24, res.scale());
        assertEquals("incorrect value", "123456789012345.678901234567890123456789", res.toString());
        res = a.scaleByPowerOfTen(-50);
        assertEquals("incorrect scale", 84, res.scale());
        assertEquals("incorrect value", "1.23456789012345678901234567890123456789E-46", res.toString());
        res = a.scaleByPowerOfTen(50);
        assertEquals("incorrect scale", -16, res.scale());
        assertEquals("incorrect value", "1.23456789012345678901234567890123456789E+54", res.toString());
        try { 
            a.scaleByPowerOfTen(Integer.MIN_VALUE + 2);
            fail("ArithmeticException is not thrown");
        } catch (ArithmeticException expected) {
        } 
        a = new BigDecimal("123456789012345678901234567890123456789E25");