Code example for BigDecimal

Methods: divide

0
 
	/** 
	 * @tests java.math.BigDecimal#divide(java.math.BigDecimal, int) 
	 */ 
	public void test_divideLjava_math_BigDecimalI() { 
		BigDecimal divd1 = new BigDecimal(value, 2);
		BigDecimal divd2 = new BigDecimal("2.335");
		BigDecimal divd3 = divd1.divide(divd2, BigDecimal.ROUND_UP);
		assertTrue("123459.08/2.335 is not correct", divd3.toString().equals(
				"52873.27") 
				&& divd3.scale() == divd1.scale());
		assertTrue(
				"the unscaledValue representation of 123459.08/2.335 is not correct", 
				divd3.unscaledValue().toString().equals("5287327"));
		divd2 = new BigDecimal(123.4D);
		divd3 = divd1.divide(divd2, BigDecimal.ROUND_DOWN);
		assertTrue("123459.08/123.4  is not correct", divd3.toString().equals(
				"1000.47") 
				&& divd3.scale() == 2);
		divd2 = new BigDecimal(000D);
 
		try { 
			divd1.divide(divd2, BigDecimal.ROUND_DOWN);
            fail("divide by zero is not caught");
		} catch (ArithmeticException e) {
		} 
	}