Code example for BigDecimal

Methods: add

0
        assertTrue("the sum of 23.456 + 3849.235 is wrong", sum.unscaledValue().toString().equals(
                "3872691") 
                && sum.scale() == 3);
        assertTrue("the sum of 23.456 + 3849.235 is not printed correctly", sum.toString().equals(
                "3872.691")); 
        BigDecimal add3 = new BigDecimal(12.34E02D);
        assertTrue("the sum of 23.456 + 12.34E02 is not printed correctly", (add1.add(add3))
                .toString().equals("1257.456"));
    } 
 
    /** 
     * @tests java.math.BigDecimal#divide(java.math.BigDecimal, 
     *        java.math.MathContext) divide(BigDecimal, RoundingMode) 
     */ 
    public void test_DivideBigDecimalRoundingModeUP() { 
        String a = "-37361671119238118911893939591735";
        String b = "74723342238476237823787879183470";
        RoundingMode rm = RoundingMode.UP;
        String c = "-1";
        BigDecimal aNumber = new BigDecimal(new BigInteger(a));
        BigDecimal bNumber = new BigDecimal(new BigInteger(b));