Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4212072

DecimalFormatSymbols.setCurrencyInstance fails to set new symbol.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.3.0
    • 1.2.0
    • core-libs
    • beta
    • generic
    • generic



      Name: gsC80088 Date: 02/16/99


      1. set a new currency symbol "F" in a DecimalFormatSymbol object
      2. call setDecimalFormatSymbols on a DecimalFormat
      3. call format on the updated DecimalFormat
      4. I expected to see the formated string "F1234.56", but instead
      the symbol doesn't appear to be updated. Instead, the output is
      "$1234.56", which seems to have ignored the new currency symbol.

      Here's the code:


      package javai18n.currency;
      import java.text.*;

      public class MixCurrency {

        public static void main(String[] args) {
          NumberFormat nfUS = NumberFormat.getCurrencyInstance(java.util.Locale.US);
          DecimalFormatSymbols symbolsFR = new DecimalFormatSymbols(java.util.Locale.FRANCE);
          String frenchCurrency = symbolsFR.getCurrencySymbol();

          DecimalFormatSymbols symbolsUS = ((DecimalFormat)nfUS).getDecimalFormatSymbols();
          symbolsUS.setCurrencySymbol(frenchCurrency);
          ((DecimalFormat)nfUS).setDecimalFormatSymbols(symbolsUS);
          double amount = 1234.56;
          System.out.println(nfUS.format(amount));

          // Although I expect the following:
          // F1,234.56
          // It simply prints the typical US pattern:
          // $1,234.56
          //
          // How can I change the currency for a format without changing
          // other parts of the pattern?
        }
      }
      (Review ID: 53519)
      ======================================================================

            aliusunw Alan Liu (Inactive)
            gstone Greg Stone
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: