// JDK gives E0
// S obeys the maximum integer digits
0 0 1 0 2.99792458E8 KS
-// JDK gives .2998E9
-0 0 0 4 2.998E8 KS
-// According to the spec, if maxInt>minInt and minInt>1, then set
-// minInt to 1 for the purposes of engineering notation; see #13289
+// JDK and S give .2998E9
+0 0 0 4 2.998E8 KSQ
- // S correctly formats this as 29.979246E7.
// JDK uses 8 + 6 for significant digits instead of 2 + 6
- // J and C return 2.9979246E8.
- // TODO: Merge trunk
- 2 8 1 6 29.979246E7 CJKQ
++// Context: #13289
+ 2 8 1 6 2.9979246E8 K
// Treat max int digits > 8 as being the same as min int digits.
// This behavior is not spelled out in the specification.
// JDK fails here because it tries to use 9 + 6 = 15 sig digits.
// JDK gives E0
// S obeys the maximum integer digits
0 0 1 0 2.99792458E8 KS
-// JDK gives .2998E9
-0 0 0 4 2.998E8 KS
+// JDK and S give .2998E9
+0 0 0 4 2.998E8 KSQ
- // S correctly formats this as 29.979246E7.
- // JDK uses 8 + 6 for significant digits instead of 2 + 6
- // J and C return 2.9979246E8.
- // TODO: Merge trunk
- 2 8 1 6 29.979246E7 CJKQ
+ // According to the spec, if maxInt>minInt and minInt>1, then set
-// minInt to 1 for the purposes of engineering notation; see #13289
-// JDK uses 8 + 6 for significant digits instead of 2 + 6
++// Context: #13289
+ 2 8 1 6 2.9979246E8 K
// Treat max int digits > 8 as being the same as min int digits.
// This behavior is not spelled out in the specification.
// JDK fails here because it tries to use 9 + 6 = 15 sig digits.
if (!Arrays.equals(symbols.getDigitStrings(), defDigitStrings)) {
errln("ERROR: Latin digits should be set" + symbols.getDigitStrings()[0]);
}
+ if (defZero != symbols.getCodePointZero()) {
+ errln("ERROR: Code point zero be ASCII 0");
+ }
}
+
+ @Test
+ public void testNumberingSystem() {
+ Object[][] cases = {
+ {"en", "latn", "1,234.56", ';'},
+ {"en", "arab", "١٬٢٣٤٫٥٦", '؛'},
+ {"en", "mathsanb", "𝟭,𝟮𝟯𝟰.𝟱𝟲", ';'},
+ {"en", "mymr", "၁,၂၃၄.၅၆", ';'},
+ {"my", "latn", "1,234.56", ';'},
+ {"my", "arab", "١٬٢٣٤٫٥٦", '؛'},
+ {"my", "mathsanb", "𝟭,𝟮𝟯𝟰.𝟱𝟲", ';'},
+ {"my", "mymr", "၁,၂၃၄.၅၆", '၊'},
+ {"en@numbers=thai", "mymr", "၁,၂၃၄.၅၆", ';'}, // conflicting numbering system
+ };
+
+ for (Object[] cas : cases) {
+ ULocale loc = new ULocale((String) cas[0]);
+ NumberingSystem ns = NumberingSystem.getInstanceByName((String) cas[1]);
+ String expectedFormattedNumberString = (String) cas[2];
+ char expectedPatternSeparator = (Character) cas[3];
+
+ DecimalFormatSymbols dfs = DecimalFormatSymbols.forNumberingSystem(loc, ns);
+ DecimalFormat df = new DecimalFormat("#,##0.##", dfs);
+ String actual1 = df.format(1234.56);
+ assertEquals("1234.56 with " + loc + " and " + ns.getName(),
+ expectedFormattedNumberString, actual1);
+ // The pattern separator is something that differs by numbering system in my@numbers=mymr.
+ char actual2 = dfs.getPatternSeparator();
+ assertEquals("Pattern separator with " + loc + " and " + ns.getName(),
+ expectedPatternSeparator, actual2);
+
+ // Coverage for JDK Locale overload
+ DecimalFormatSymbols dfs2 = DecimalFormatSymbols.forNumberingSystem(loc.toLocale(), ns);
+ assertEquals("JDK Locale and ICU Locale should produce the same object", dfs, dfs2);
+ }
+ }
}
}
}
+ @Test
+ public void Test13148() {
+ if (logKnownIssue("13148", "Currency separators used in non-currency parsing")) return;
+ DecimalFormat fmt = (DecimalFormat)NumberFormat.getInstance(new ULocale("en", "ZA"));
+ DecimalFormatSymbols symbols = fmt.getDecimalFormatSymbols();
+ symbols.setDecimalSeparator('.');
+ symbols.setGroupingSeparator(',');
+ fmt.setDecimalFormatSymbols(symbols);
+ ParsePosition ppos = new ParsePosition(0);
+ Number number = fmt.parse("300,000", ppos);
+ assertEquals("Should parse to 300000 using non-monetary separators: " + ppos, 300000L, number);
+ }
+
+ @Test
+ public void Test13289() {
+ DecimalFormat df = new DecimalFormat("#00.0#E0");
+ String result = df.format(0.00123);
+ assertEquals("Should ignore scientific minInt if maxInt>minInt", "1.23E-3", result);
+ }
+
@Test
public void testPercentZero() {
DecimalFormat df = (DecimalFormat) NumberFormat.getPercentInstance();