Code example for BigDecimal

Methods: multiply

0
	 
	@Test 
	public void imporatant() { 
		int divisor = 3;
		BigDecimal x = BigDecimal.ONE.divide(new BigDecimal(divisor), MathContext.DECIMAL128);
		BigDecimal oneABe = x.multiply(new BigDecimal(divisor), MathContext.DECIMAL128);
		oneABe = oneABe.setScale(4, RoundingMode.HALF_EVEN);
		assertTrue("Precision lost! 1'a be: " + oneABe, BigDecimal.ONE.compareTo(oneABe) == 0);
	} 
	 
	@Test 
	public void lessImportant() { 
		int divisor = 13;
		double x = BigDecimal.ONE.divide(new BigDecimal(divisor), MathContext.DECIMAL128).doubleValue();
		BigDecimal oneABe = new BigDecimal(x).multiply(new BigDecimal(divisor), MathContext.DECIMAL128);
		oneABe = oneABe.setScale(4, RoundingMode.FLOOR);
		assertTrue("Precision lost! 1'a be: " + oneABe, BigDecimal.ONE.compareTo(oneABe) == 0);
	} 
 
}