Code example for BigDecimal

Methods: scalescaleByPowerOfTentoString

0
     * scaleByPowerOfTen(int n) 
     */ 
    public void testScaleByPowerOfTen1() { 
        String a = "1231212478987482988429808779810457634781384756794987";
        int aScale = 13;
        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
        BigDecimal result = aNumber.scaleByPowerOfTen(10);
        String res = "1231212478987482988429808779810457634781384756794.987";
        int resScale = 3;
        assertEquals("incorrect value", res, result.toString());
        assertEquals("incorrect scale", resScale, result.scale());
    } 
 
    /** 
     * scaleByPowerOfTen(int n) 
     */ 
    public void testScaleByPowerOfTen2() { 
        String a = "1231212478987482988429808779810457634781384756794987";
        int aScale = -13;
        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
        BigDecimal result = aNumber.scaleByPowerOfTen(10);