]> granicus.if.org Git - icu/commitdiff
ICU-11787 Add support for STANDARDCURRENCYSTYLE and locale u-ext key -cf- (J)
authorPeter Edberg <pedberg@unicode.org>
Thu, 10 Sep 2015 07:01:41 +0000 (07:01 +0000)
committerPeter Edberg <pedberg@unicode.org>
Thu, 10 Sep 2015 07:01:41 +0000 (07:01 +0000)
X-SVN-Rev: 37941

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

index 93ef87af8290179c67fe5a795319ed68e01a287d..8a6fcc1f8c0cf7545b6c6f810c53d88fb73bc1c5 100644 (file)
@@ -175,8 +175,10 @@ public abstract class NumberFormat extends UFormat {
      */
     public static final int NUMBERSTYLE = 0;
     /**
-     * {@icu} Constant to specify currency style of format which uses currency symbol
-     * to represent currency, for example: "$3.00".
+     * {@icu} Constant to specify general currency style of format. Defaults to
+     * STANDARDCURRENCYSTYLE, using currency symbol, for example "$3.00", with
+     * non-accounting style for negative values (e.g. minus sign).
+     * The specific style may be specified using the -cf- locale key.
      * @stable ICU 4.2
      */
     public static final int CURRENCYSTYLE = 1;
@@ -212,6 +214,7 @@ public abstract class NumberFormat extends UFormat {
      * {@icu} Constant to specify currency style of format which uses currency symbol
      * to represent currency for accounting, for example: "($3.00), instead of
      * "-$3.00" ({@link #CURRENCYSTYLE}).
+     * Overrides any style specified using -cf- key in locale.
      * @stable ICU 53
      */
     public static final int ACCOUNTINGCURRENCYSTYLE = 7;
@@ -223,6 +226,14 @@ public abstract class NumberFormat extends UFormat {
      */
     public static final int CASHCURRENCYSTYLE = 8;
     /**
+     * {@icu} Constant to specify currency style of format which uses currency symbol
+     * to represent currency, for example "$3.00", using non-accounting style for
+     * negative values (e.g. minus sign).
+     * Overrides any style specified using -cf- key in locale.
+     * @draft ICU 56
+     * @provisional This API might change or be removed in a future release. 
+     */
+    public static final int STANDARDCURRENCYSTYLE = 9;
 
     /**
      * Field constant used to construct a FieldPosition object. Signifies that
@@ -1304,13 +1315,14 @@ public abstract class NumberFormat extends UFormat {
      *                                   NUMBERSTYLE, CURRENCYSTYLE,
      *                                   PERCENTSTYLE, SCIENTIFICSTYLE,
      *                                   INTEGERSTYLE, ISOCURRENCYSTYLE,
-     *                                   PLURALCURRENCYSTYLE and ACCOUNTSTYLE.
+     *                                   PLURALCURRENCYSTYLE, ACCOUNTINGCURRENCYSTYLE.
+     *                                   CASHCURRENCYSTYLE, STANDARDCURRENCYSTYLE.
      * @stable ICU 4.2
      */
     public static NumberFormat getInstance(ULocale desiredLocale, int choice) {
-        if (choice < NUMBERSTYLE || choice > CASHCURRENCYSTYLE) {
+        if (choice < NUMBERSTYLE || choice > STANDARDCURRENCYSTYLE) {
             throw new IllegalArgumentException(
-                "choice should be from NUMBERSTYLE to PLURALCURRENCYSTYLE");
+                "choice should be from NUMBERSTYLE to STANDARDCURRENCYSTYLE");
         }
 //          if (shim == null) {
 //              return createInstance(desiredLocale, choice);
@@ -1338,7 +1350,7 @@ public abstract class NumberFormat extends UFormat {
         // For currency plural format, the pattern is get from
         // the locale (from CurrencyUnitPatterns) without override.
         if (choice == CURRENCYSTYLE || choice == ISOCURRENCYSTYLE || choice == ACCOUNTINGCURRENCYSTYLE
-                || choice == CASHCURRENCYSTYLE) {
+                || choice == CASHCURRENCYSTYLE || choice == STANDARDCURRENCYSTYLE) {
             String temp = symbols.getCurrencyPattern();
             if(temp!=null){
                 pattern = temp;
@@ -1488,9 +1500,13 @@ public abstract class NumberFormat extends UFormat {
             patternKey = "decimalFormat";
             break;
         case CURRENCYSTYLE:
+            String cfKeyValue = forLocale.getKeywordValue("cf");
+            patternKey = (cfKeyValue != null && cfKeyValue.equals("account"))? "accountingFormat": "currencyFormat";
+            break;
         case CASHCURRENCYSTYLE:
         case ISOCURRENCYSTYLE:
         case PLURALCURRENCYSTYLE:
+        case STANDARDCURRENCYSTYLE:
             patternKey = "currencyFormat";
             break;
         case PERCENTSTYLE:
index 2f3c602e6aabfbb6b8c66aae03ce829a705da974..1c0a16adfe7ed4d7b7b5e5fb34cac3592f6e88b5 100644 (file)
@@ -3245,7 +3245,7 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
      */
     public void TestGetInstance() {
         // Tests "public final static NumberFormat getInstance(int style)"
-        int maxStyle = NumberFormat.CASHCURRENCYSTYLE;
+        int maxStyle = NumberFormat.STANDARDCURRENCYSTYLE;
 
         int[] invalid_cases = { NumberFormat.NUMBERSTYLE - 1, NumberFormat.NUMBERSTYLE - 2,
                 maxStyle + 1, maxStyle + 2 };
@@ -4099,22 +4099,37 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
 
     public void TestAccountingCurrency() {
         String[][] tests = {
-                {"en_US", "1234.5", "$1,234.50", "true"},
-                {"en_US", "-1234.5", "($1,234.50)", "true"},
-                {"en_US", "0", "$0.00", "true"},
-                {"en_US", "-0.2", "($0.20)", "true"},
-                {"ja_JP", "10000", "¥10,000", "true"},
-                {"ja_JP", "-1000.5", "(¥1,000)", "false"},
-                {"de_DE", "-23456.7", "-23.456,70\u00A0€", "true"},
+                //locale              num         curr fmt per loc     curr std fmt         curr acct fmt        rt
+                {"en_US",             "1234.5",   "$1,234.50",         "$1,234.50",         "$1,234.50",         "true"},
+                {"en_US@cf=account",  "1234.5",   "$1,234.50",         "$1,234.50",         "$1,234.50",         "true"},
+                {"en_US",             "-1234.5",  "-$1,234.50",        "-$1,234.50",        "($1,234.50)",       "true"},
+                {"en_US@cf=standard", "-1234.5",  "-$1,234.50",        "-$1,234.50",        "($1,234.50)",       "true"},
+                {"en_US@cf=account",  "-1234.5",  "($1,234.50)",       "-$1,234.50",        "($1,234.50)",       "true"},
+                {"en_US",             "0",        "$0.00",             "$0.00",             "$0.00",             "true"},
+                {"en_US",             "-0.2",     "-$0.20",            "-$0.20",            "($0.20)",           "true"},
+                {"en_US@cf=standard", "-0.2",     "-$0.20",            "-$0.20",            "($0.20)",           "true"},
+                {"en_US@cf=account",  "-0.2",     "($0.20)",           "-$0.20",            "($0.20)",           "true"},
+                {"ja_JP",             "10000",    "¥10,000",          "¥10,000",          "¥10,000",          "true" },
+                {"ja_JP",             "-1000.5",  "-¥1,000",          "-¥1,000",          "(¥1,000)",         "false"},
+                {"ja_JP@cf=account",  "-1000.5",  "(¥1,000)",         "-¥1,000",          "(¥1,000)",         "false"},
+                {"de_DE",             "-23456.7", "-23.456,70\u00A0€", "-23.456,70\u00A0€", "-23.456,70\u00A0€", "true" },
         };
         for (String[] data : tests) {
             ULocale loc = new ULocale(data[0]);
             double num = Double.parseDouble(data[1]);
-            String fmt = data[2];
-            boolean rt = Boolean.parseBoolean(data[3]);
+            String fmtPerLocExpected   = data[2];
+            String fmtStandardExpected = data[3];
+            String fmtAccountExpected  = data[4];
+            boolean rt = Boolean.parseBoolean(data[5]);
 
-            NumberFormat acfmt = NumberFormat.getInstance(loc, NumberFormat.ACCOUNTINGCURRENCYSTYLE);
-            expect(acfmt, num, fmt, rt);
+            NumberFormat fmtPerLoc = NumberFormat.getInstance(loc, NumberFormat.CURRENCYSTYLE);
+            expect(fmtPerLoc, num, fmtPerLocExpected, rt);
+
+            NumberFormat fmtStandard = NumberFormat.getInstance(loc, NumberFormat.STANDARDCURRENCYSTYLE);
+            expect(fmtStandard, num, fmtStandardExpected, rt);
+
+            NumberFormat fmtAccount = NumberFormat.getInstance(loc, NumberFormat.ACCOUNTINGCURRENCYSTYLE);
+            expect(fmtAccount, num, fmtAccountExpected, rt);
         }
     }