* maximum fraction digits. Note that it is not possible to specify maximium integer digits in the
* pattern except in scientific notation.
*
+ * <p>If minimum and maximum integer, fraction, or significant digits conflict with each other,
+ * the most recently specified value is used. For example, if there is a formatter with minInt=5,
+ * and then you set maxInt=3, then minInt will be changed to 3.
+ *
* @param value The minimum number of digits before the decimal separator.
* @category Rounding
* @stable ICU 2.0
*/
@Override
public synchronized void setMinimumIntegerDigits(int value) {
+ // For backwards compatibility, conflicting min/max need to keep the most recent setting.
+ int max = properties.getMaximumIntegerDigits();
+ if (max >= 0 && max < value) {
+ properties.setMaximumIntegerDigits(value);
+ }
properties.setMinimumIntegerDigits(value);
refreshFormatter();
}
* maximum fraction digits. Note that it is not possible to specify maximium integer digits in the
* pattern except in scientific notation.
*
+ * <p>If minimum and maximum integer, fraction, or significant digits conflict with each other,
+ * the most recently specified value is used. For example, if there is a formatter with minInt=5,
+ * and then you set maxInt=3, then minInt will be changed to 3.
+ *
* @param value The maximum number of digits before the decimal separator.
* @category Rounding
* @stable ICU 2.0
*/
@Override
public synchronized void setMaximumIntegerDigits(int value) {
+ int min = properties.getMinimumIntegerDigits();
+ if (min >= 0 && min > value) {
+ properties.setMinimumIntegerDigits(value);
+ }
properties.setMaximumIntegerDigits(value);
refreshFormatter();
}
* maximum fraction digits. Note that it is not possible to specify maximium integer digits in the
* pattern except in scientific notation.
*
+ * <p>If minimum and maximum integer, fraction, or significant digits conflict with each other,
+ * the most recently specified value is used. For example, if there is a formatter with minInt=5,
+ * and then you set maxInt=3, then minInt will be changed to 3.
+ *
* <p>See {@link #setRoundingIncrement} and {@link #setMaximumSignificantDigits} for two other
* ways of specifying rounding strategies.
*
*/
@Override
public synchronized void setMinimumFractionDigits(int value) {
+ int max = properties.getMaximumFractionDigits();
+ if (max >= 0 && max < value) {
+ properties.setMaximumFractionDigits(value);
+ }
properties.setMinimumFractionDigits(value);
refreshFormatter();
}
* maximum fraction digits. Note that it is not possible to specify maximium integer digits in the
* pattern except in scientific notation.
*
+ * <p>If minimum and maximum integer, fraction, or significant digits conflict with each other,
+ * the most recently specified value is used. For example, if there is a formatter with minInt=5,
+ * and then you set maxInt=3, then minInt will be changed to 3.
+ *
* @param value The maximum number of integer digits after the decimal separator.
* @see #setRoundingMode
* @category Rounding
*/
@Override
public synchronized void setMaximumFractionDigits(int value) {
+ int min = properties.getMinimumFractionDigits();
+ if (min >= 0 && min > value) {
+ properties.setMinimumFractionDigits(value);
+ }
properties.setMaximumFractionDigits(value);
refreshFormatter();
}
* <p>For example, if minimum significant digits is 3 and the number is 1.2, the number will be
* printed as "1.20".
*
+ * <p>If minimum and maximum integer, fraction, or significant digits conflict with each other,
+ * the most recently specified value is used. For example, if there is a formatter with minInt=5,
+ * and then you set maxInt=3, then minInt will be changed to 3.
+ *
* @param value The minimum number of significant digits to display.
* @see #setSignificantDigitsMode
* @category Rounding
* @stable ICU 3.0
*/
public synchronized void setMinimumSignificantDigits(int value) {
+ int max = properties.getMaximumSignificantDigits();
+ if (max >= 0 && max < value) {
+ properties.setMaximumSignificantDigits(value);
+ }
properties.setMinimumSignificantDigits(value);
refreshFormatter();
}
* <p>For example, if maximum significant digits is 3 and the number is 12345, the number will be
* printed as "12300".
*
+ * <p>If minimum and maximum integer, fraction, or significant digits conflict with each other,
+ * the most recently specified value is used. For example, if there is a formatter with minInt=5,
+ * and then you set maxInt=3, then minInt will be changed to 3.
+ *
* <p>See {@link #setRoundingIncrement} and {@link #setMaximumFractionDigits} for two other ways
* of specifying rounding strategies.
*
* @stable ICU 3.0
*/
public synchronized void setMaximumSignificantDigits(int value) {
+ int min = properties.getMinimumSignificantDigits();
+ if (min >= 0 && min > value) {
+ properties.setMinimumSignificantDigits(value);
+ }
properties.setMaximumSignificantDigits(value);
refreshFormatter();
}
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.text.AttributedCharacterIterator;
// For valid array, it is displayed as {min value, max value}
// Tests when "if (minimumIntegerDigits > maximumIntegerDigits)" is true
int[][] cases = { { -1, 0 }, { 0, 1 }, { 1, 0 }, { 2, 0 }, { 2, 1 }, { 10, 0 } };
- int[] expectedMax = { 1, 1, 1, 2, 2, 10 };
+ int[] expectedMax = { 1, 1, 0, 0, 1, 0 };
if (cases.length != expectedMax.length) {
errln("Can't continue test case method TestSetMinimumIntegerDigits "
+ "since the test case arrays are unequal.");
}
}
+ @Test
+ public void TestMinMaxOverrides()
+ throws IllegalAccessException, IllegalArgumentException, InvocationTargetException,
+ NoSuchMethodException, SecurityException {
+ Class<?>[] baseClasses = {NumberFormat.class, NumberFormat.class, DecimalFormat.class};
+ String[] names = {"Integer", "Fraction", "Significant"};
+ for (int i = 0; i < 3; i++) {
+ DecimalFormat df = new DecimalFormat();
+ Class<?> base = baseClasses[i];
+ String name = names[i];
+ Method getMinimum = base.getDeclaredMethod("getMinimum" + name + "Digits");
+ Method setMinimum = base.getDeclaredMethod("setMinimum" + name + "Digits", Integer.TYPE);
+ Method getMaximum = base.getDeclaredMethod("getMaximum" + name + "Digits");
+ Method setMaximum = base.getDeclaredMethod("setMaximum" + name + "Digits", Integer.TYPE);
+
+ // Check max overrides min
+ setMinimum.invoke(df, 2);
+ assertEquals(name + " getMin A", 2, getMinimum.invoke(df));
+ setMaximum.invoke(df, 3);
+ assertEquals(name + " getMin B", 2, getMinimum.invoke(df));
+ assertEquals(name + " getMax B", 3, getMaximum.invoke(df));
+ setMaximum.invoke(df, 2);
+ assertEquals(name + " getMin C", 2, getMinimum.invoke(df));
+ assertEquals(name + " getMax C", 2, getMaximum.invoke(df));
+ setMaximum.invoke(df, 1);
+ assertEquals(name + " getMin D", 1, getMinimum.invoke(df));
+ assertEquals(name + " getMax D", 1, getMaximum.invoke(df));
+
+ // Check min overrides max
+ setMaximum.invoke(df, 2);
+ assertEquals(name + " getMax E", 2, getMaximum.invoke(df));
+ setMinimum.invoke(df, 1);
+ assertEquals(name + " getMin F", 1, getMinimum.invoke(df));
+ assertEquals(name + " getMax F", 2, getMaximum.invoke(df));
+ setMinimum.invoke(df, 2);
+ assertEquals(name + " getMin G", 2, getMinimum.invoke(df));
+ assertEquals(name + " getMax G", 2, getMaximum.invoke(df));
+ setMinimum.invoke(df, 3);
+ assertEquals(name + " getMin H", 3, getMinimum.invoke(df));
+ assertEquals(name + " getMax H", 3, getMaximum.invoke(df));
+ }
+ }
+
@Test
public void Test10436() {
DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(Locale.ENGLISH);