ICU-13289 Fixing engineering notation discrepancy with the LDML spec.

X-SVN-Rev: 40304
This commit is contained in:
Shane Carr 2017-08-01 18:12:59 +00:00
parent 52513beddd
commit ea6b6a46b1
4 changed files with 22 additions and 8 deletions

View 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

View 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;

View 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

View 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();