]> granicus.if.org Git - icu/commitdiff
ICU-13060 Addressing comments from #11649 and #11816
authorShane Carr <shane@unicode.org>
Mon, 27 Mar 2017 23:06:56 +0000 (23:06 +0000)
committerShane Carr <shane@unicode.org>
Mon, 27 Mar 2017 23:06:56 +0000 (23:06 +0000)
X-SVN-Rev: 39947

icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormat.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/NumberFormatTest.java

index f482d26f790b6cb0dc3b5ec594cb88e0dec7a142..1a0154e2e19420a33d0e1f77f212f5a2721fd659 100644 (file)
@@ -755,6 +755,22 @@ public class DecimalFormat extends NumberFormat {
    * Sets whether to always shown the plus sign ('+' in <em>en</em>) on positive numbers. The rules
    * in UTS #35 section 3.2.1 will be followed to ensure a locale-aware placement of the sign.
    *
+   * <p>More specifically, the following strategy will be used to place the plus sign:
+   *
+   * <ol>
+   *   <li><em>Patterns without a negative subpattern:</em> The locale's plus sign will be prepended
+   *       to the positive prefix.
+   *   <li><em>Patterns with a negative subpattern without a '-' sign (e.g., accounting):</em> The
+   *       locale's plus sign will be prepended to the positive prefix, as in case 1.
+   *   <li><em>Patterns with a negative subpattern that has a '-' sign:</em> The locale's plus sign
+   *       will substitute the '-' in the negative subpattern. The positive subpattern will be
+   *       unused.
+   * </ol>
+   *
+   * This method is designed to be used <em>instead of</em> applying a pattern containing an
+   * explicit plus sign, such as "+0;-0". The behavior when combining this method with explicit plus
+   * signs in the pattern is undefined.
+   *
    * @param value true to always show a sign; false to hide the sign on positive numbers.
    * @category Affixes
    * @internal
index cef0e73e0e5ac35fdebe6cb1ecd08855e21ccc47..0ac2e58baccf639a9809a2aad947e7b17830bb4a 100644 (file)
@@ -4829,6 +4829,13 @@ public class NumberFormatTest extends TestFmwk {
         DecimalFormat fmt2 = new DecimalFormat(newPattern);
         fmt2.setCurrency(Currency.getInstance("USD"));
         assertEquals("Triple currency sign pattern should round-trip", "US dollars 12.34", fmt2.format(12.34));
+
+        String quotedPattern = "\u00a4\u00a4'\u00a4' 0.00";
+        DecimalFormat fmt3 = new DecimalFormat(quotedPattern);
+        assertEquals("Should be treated as double currency sign", "USD\u00a4 12.34", fmt3.format(12.34));
+
+        String outQuotedPattern = fmt3.toPattern();
+        assertEquals("Double currency sign with quoted sign should round-trip", quotedPattern, outQuotedPattern);
     }
 
     @Test