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

NumberFormat gives incorrect currency symbol using a custom locale

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.2.2
    • core-libs
    • x86
    • windows_nt



      Name: rlT66838 Date: 12/06/99


      Classic VM (build JDK-1.2.2-001, native threads, symcjit)


      I'm sending this test program in as I think it shows what I
      think is a bug in the implementation of NumberFormat.

      If I give a NumberFormat a custom locale, it seems to base the
      decision on which currency symbol to use on the language
      portion of the Locale rather than the country. For example
      if I give es-US which I would expect to represent a spanish
      speaker in the US, I get currency formatted in pesetas rather
      than the expected dollars.

      Also if you create a locale with just a country (not shown in
      the test program), NumberFormat returns the currency symbol for the
      default locale rather than country you give it.

      e.g if I create a locale using new Locale("", "US") I get the symbol
      for the UK rather than the US.

      (The test program was written using JDK 1.2.2 under Win32, and it was also
       tested using jre 1.1.7b with the same behaviour). I am currently based
       in the UK so the default locale for me is en-GB)


      import java.util.*;
      import java.text.*;
      import java.math.*;

      public class TestNumberFormat
      {
          public static void main(String[] args)
          {
              Locale locale1 = new Locale("en", "US");
              NumberFormat fmt1 = NumberFormat.getCurrencyInstance(locale1);

              BigDecimal d = new BigDecimal("1000.00");

              Locale locale2 = new Locale("es","US");
              NumberFormat fmt2 = NumberFormat.getCurrencyInstance(locale2);

              // The should be in dollars.
              System.out.println("Amount in: " + locale1 + " is " + fmt1.format(d));
              System.out.println(locale1.getDisplayName());

              // But according to the number formater spanish speakers in
              // the US use pesetas.
              System.out.println("Amount in: " + locale2 + " is " + fmt2.format(d));
              System.out.println(locale2.getDisplayName());
          }
      }
      (Review ID: 98693)
      ======================================================================

            nlindenbsunw Norbert Lindenberg (Inactive)
            rlewis Roger Lewis (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: