/**
* Sets the character used for zero.
* <p>
- * <b>Note:</b> When the specified zeroDigit is a Unicode decimal digit character
- * (category:Nd) and the number value is 0, then this method propagate digit 1 to
+ * <b>Note:</b> This method propagates digit 1 to
* digit 9 by incrementing code point one by one.
*
* @param zeroDigit the zero character.
digitStrings[0] = String.valueOf(zeroDigit);
digits[0] = zeroDigit;
- // Propagate digit 1 - 9 only when the input zeroDigit is a
- // Unicode number and its integer value is 0.
-
- if (Character.digit(zeroDigit, 10) == 0) {
- for (int i = 1; i < 10; i++) {
- char d = (char)(zeroDigit + i);
- digitStrings[i] = String.valueOf(d);
- digits[i] = d;
- }
+ // Always propagate to digits 1-9 for JDK and ICU4C consistency.
+ for (int i = 1; i < 10; i++) {
+ char d = (char)(zeroDigit + i);
+ digitStrings[i] = String.valueOf(d);
+ digits[i] = d;
}
}
import org.junit.Test;
+import com.ibm.icu.text.DecimalFormat;
import com.ibm.icu.text.DecimalFormatSymbols;
import com.ibm.icu.util.Currency;
import com.ibm.icu.util.ULocale;
}
}
+ @Test
+ public void testPropagateZeroDigit() {
+ DecimalFormatSymbols dfs = new DecimalFormatSymbols();
+ dfs.setZeroDigit('\u1040');
+ DecimalFormat df = new DecimalFormat("0");
+ df.setDecimalFormatSymbols(dfs);
+ assertEquals("Should propagate char with number property zero",
+ '\u1041', dfs.getDigits()[1]);
+ assertEquals("Should propagate char with number property zero",
+ "\u1044\u1040\u1041\u1042\u1043", df.format(40123));
+ dfs.setZeroDigit('a');
+ df.setDecimalFormatSymbols(dfs);
+ assertEquals("Should propagate char WITHOUT number property zero",
+ 'b', dfs.getDigits()[1]);
+ assertEquals("Should propagate char WITHOUT number property zero",
+ "eabcd", df.format(40123));
+ }
+
@Test
public void testDigitSymbols() {
final char defZero = '0';