]> granicus.if.org Git - icu/commitdiff
ICU-13289 Fixing engineering notation discrepancy with the LDML spec.
authorShane Carr <shane@unicode.org>
Tue, 1 Aug 2017 18:12:59 +0000 (18:12 +0000)
committerShane Carr <shane@unicode.org>
Tue, 1 Aug 2017 18:12:59 +0000 (18:12 +0000)
X-SVN-Rev: 40304

icu4c/source/test/testdata/numberformattestspecification.txt
icu4j/main/classes/core/src/com/ibm/icu/impl/number/formatters/ScientificFormat.java
icu4j/main/tests/core/src/com/ibm/icu/dev/data/numberformattestspecification.txt
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/NumberFormatTest.java

index 5200bc83d6f70cba33811490936351c05690f18c..fe262fa1f9b876c7c4520dde690fd7576c05150e 100644 (file)
@@ -358,14 +358,15 @@ minIntegerDigits  maxIntegerDigits        minFractionDigits       maxFractionDigits       output  bre
 0      0       1       0       2.99792458E8    KS
 // JDK gives .2998E9
 0      0       0       4       2.998E8 KS
-// S correctly formats this as 29.979246E7.
+// 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
-// J and C return 2.9979246E8.
-2      8       1       6       29.979246E7     CJK
+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.
-2      9       1       6       29.979246E7     K
+// C and J get 29.979246E7
+2      9       1       6       2.9979246E8     CJK
 
 test significant digits scientific
 set locale en
index f62820199bf0bf07aa15d3b14540a6dbbdcd8350..c2e71c80cc0dce3b629c07e8575ff63db3884ab8 100644 (file)
@@ -149,6 +149,11 @@ public class ScientificFormat extends Format.BeforeFormat implements Rounder.Mul
     // (see #13118). Note that the bound 8 on integer digits is historic.
     int _maxInt = properties.getMaximumIntegerDigits();
     int _minInt = properties.getMinimumIntegerDigits();
+    // Bug #13289: if maxInt > minInt > 1, then minInt should be 1 for the
+    // purposes of engineering notatation.
+    if (_maxInt > _minInt && _minInt > 1) {
+        _minInt = 1;
+    }
     minInt = _minInt < 0 ? 0 : _minInt >= 8 ? 1 : _minInt;
     maxInt = _maxInt < _minInt ? _minInt : _maxInt >= 8 ? _minInt : _maxInt;
     assert 0 <= minInt && minInt <= maxInt && maxInt < 8;
index 5200bc83d6f70cba33811490936351c05690f18c..fe262fa1f9b876c7c4520dde690fd7576c05150e 100644 (file)
@@ -358,14 +358,15 @@ minIntegerDigits  maxIntegerDigits        minFractionDigits       maxFractionDigits       output  bre
 0      0       1       0       2.99792458E8    KS
 // JDK gives .2998E9
 0      0       0       4       2.998E8 KS
-// S correctly formats this as 29.979246E7.
+// 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
-// J and C return 2.9979246E8.
-2      8       1       6       29.979246E7     CJK
+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.
-2      9       1       6       29.979246E7     K
+// C and J get 29.979246E7
+2      9       1       6       2.9979246E8     CJK
 
 test significant digits scientific
 set locale en
index d84527181935a4f3c9366e1d3937acd51ab1e365..21c190c5e8236dde9739582190ea946d09a73c19 100644 (file)
@@ -5227,6 +5227,13 @@ public class NumberFormatTest extends TestFmwk {
         }
     }
 
+    @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();