*
* @param multiplier The number by which all numbers passed to {@link #format} will be multiplied.
* @throws IllegalArgumentException If the given multiplier is zero.
+ * @throws ArithmeticException when inverting multiplier produces a non-terminating decimal result
+ * in conjunction with MathContext of unlimited precision.
* @category Multipliers
* @stable ICU 2.0
*/
* method.
*
* @param mathContext The MathContext to use when rounding numbers.
+ * @throws ArithmeticException when inverting multiplier produces a non-terminating decimal result
+ * in conjunction with MathContext of unlimited precision.
* @see java.math.MathContext
* @category Rounding
* @stable ICU 4.2
* {@link com.ibm.icu.math.MathContext}.
*
* @param mathContextICU The MathContext to use when rounding numbers.
+ * @throws ArithmeticException when inverting multiplier produces a non-terminating decimal result
+ * in conjunction with MathContext of unlimited precision.
* @see #setMathContext(java.math.MathContext)
* @category Rounding
* @stable ICU 4.2
df.setMathContext(fourDigits);
BigInteger actual4Digits = ((BigDecimal) df.parse(hugeNumberString)).toBigIntegerExact();
assertEquals("Extreme division with fourDigits", huge4Digits, actual4Digits);
+ }
+
+ /**
+ * ArithmeticException is thrown when inverting multiplier produces a non-terminating
+ * decimal result in conjunction with MathContext of unlimited precision.
+ */
+ @Test
+ public void testSetMathContextArithmeticException() {
+ DecimalFormat df = new DecimalFormat();
+ df.setMultiplier(7);
+ try {
+ df.setMathContext(java.math.MathContext.UNLIMITED);
+ fail("Extreme division with unlimited precision should throw ArithmeticException");
+ } catch (ArithmeticException e) {
+ // expected
+ }
+ }
+
+ /**
+ * ArithmeticException is thrown when inverting multiplier produces a non-terminating
+ * decimal result in conjunction with MathContext of unlimited precision.
+ */
+ @Test
+ public void testSetMathContextICUArithmeticException() {
+ DecimalFormat df = new DecimalFormat();
+ df.setMultiplier(7);
+ try {
+ df.setMathContextICU(new MathContext(0));
+ fail("Extreme division with unlimited precision should throw ArithmeticException");
+ } catch (ArithmeticException e) {
+ // expected
+ }
+ }
+
+ /**
+ * ArithmeticException is thrown when inverting multiplier produces a non-terminating
+ * decimal result in conjunction with MathContext of unlimited precision.
+ */
+ @Test
+ public void testSetMultiplierArithmeticException() {
+ DecimalFormat df = new DecimalFormat();
+ df.setMathContext(java.math.MathContext.UNLIMITED);
try {
- df.setMathContext(unlimitedCeiling);
- df.parse(hugeNumberString);
- fail("Extreme division with unlimitedCeiling should throw ArithmeticException");
+ df.setMultiplier(7);
+ fail("Extreme division with unlimited precision should throw ArithmeticException");
} catch (ArithmeticException e) {
// expected
}