Code example for BigDecimal

Methods: divide

0
 
	/** 
	 * @tests java.math.BigDecimal#divide(java.math.BigDecimal, int, int) 
	 */ 
	public void test_divideLjava_math_BigDecimalII() { 
		BigDecimal divd1 = new BigDecimal(value2, 4);
		BigDecimal divd2 = new BigDecimal("0.0023");
		BigDecimal divd3 = divd1.divide(divd2, 3, BigDecimal.ROUND_HALF_UP);
		assertTrue("1233456/0.0023 is not correct", divd3.toString().equals(
				"536285217.391") 
				&& divd3.scale() == 3);
		divd2 = new BigDecimal(1345.5E-02D);
		divd3 = divd1.divide(divd2, 0, BigDecimal.ROUND_DOWN);
		assertTrue(
				"1233456/13.455 is not correct or does not have the correct scale", 
				divd3.toString().equals("91672") && divd3.scale() == 0);
		divd2 = new BigDecimal(0000D);
 
		try { 
			divd1.divide(divd2, 4, BigDecimal.ROUND_DOWN);
            fail("divide by zero is not caught");
		} catch (ArithmeticException e) {
		} 
	}