ICU-13808 Document ArithmeticException thrown by DecimalFormat
- Document the exception in the following methods setMultiplier, setMathContext, setMathContextICU - Add test to check the documented behavior
This commit is contained in:
parent
dbd9065c69
commit
ac0c7bbe3c
@ -1123,6 +1123,8 @@ public class DecimalFormat extends NumberFormat {
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
@ -1296,6 +1298,8 @@ public class DecimalFormat extends NumberFormat {
|
||||
* 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
|
||||
@ -1330,6 +1334,8 @@ public class DecimalFormat extends NumberFormat {
|
||||
* {@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
|
||||
|
@ -4962,10 +4962,51 @@ public class NumberFormatTest extends TestFmwk {
|
||||
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(unlimitedCeiling);
|
||||
df.parse(hugeNumberString);
|
||||
fail("Extreme division with unlimitedCeiling should throw ArithmeticException");
|
||||
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.setMultiplier(7);
|
||||
fail("Extreme division with unlimited precision should throw ArithmeticException");
|
||||
} catch (ArithmeticException e) {
|
||||
// expected
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user