ICU-11621 Fix for decimal not showing when no fraction but always show decimal separator set

X-SVN-Rev: 38535
This commit is contained in:
Stuart Gill 2016-03-17 23:22:32 +00:00
parent c8a1194dd2
commit 21d60734f6
2 changed files with 23 additions and 2 deletions

View file

@ -1718,12 +1718,12 @@ public class DecimalFormat extends NumberFormat {
}
result.append(decimal);
// [Spark/CDL] Add attribute for decimal separator
fracBegin = result.length();
if (parseAttr) {
// Length of decimal separator is 1.
int decimalSeparatorBegin = result.length() - 1;
addAttribute(Field.DECIMAL_SEPARATOR, decimalSeparatorBegin,
result.length());
fracBegin = result.length();
}
// Record field information for caller.
if (fieldPosition.getField() == NumberFormat.FRACTION_FIELD) {
@ -1748,6 +1748,11 @@ public class DecimalFormat extends NumberFormat {
result.append(digits[0]);
}
// http://bugs.icu-project.org/trac/ticket/11621
if ((fracBegin == -1) && this.decimalSeparatorAlwaysShown) {
result.append(decimal);
}
// Record field information
if (fieldPosition.getField() == NumberFormat.INTEGER_FIELD) {
if (fieldPosition.getEndIndex() < 0) {

View file

@ -555,7 +555,7 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
}
}
}
public void Test10419RoundingWith0FractionDigits() {
Object[][] data = new Object[][]{
{BigDecimal.ROUND_CEILING, 1.488, "2"},
@ -4527,4 +4527,20 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
assertEquals("End index: ", 11, iterator.getEndIndex());
}
// Test that the decimal is shown even when there are no fractional digits
public void Test11621() throws Exception {
String pat = "0.##E0";
DecimalFormatSymbols icuSym = new DecimalFormatSymbols(Locale.US);
DecimalFormat icuFmt = new DecimalFormat(pat, icuSym);
icuFmt.setDecimalSeparatorAlwaysShown(true);
String icu = ((NumberFormat)icuFmt).format(299792458);
java.text.DecimalFormatSymbols jdkSym = new java.text.DecimalFormatSymbols(Locale.US);
java.text.DecimalFormat jdkFmt = new java.text.DecimalFormat(pat,jdkSym);
jdkFmt.setDecimalSeparatorAlwaysShown(true);
String jdk = ((java.text.NumberFormat)jdkFmt).format(299792458);
assertEquals("ICU and JDK placement of decimal in exponent", jdk, icu);
}
}