JDK-4256919 : NumberFormat instance for French locale displays funny characters
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 1.2.2
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: solaris_2.5
  • CPU: sparc
  • Submitted: 1999-07-25
  • Updated: 2000-04-07
  • Resolved: 2000-04-07
Related Reports
Relates :  
Description
The following code (which can be found in the Java Tutorial at http://java.sun.com/docs/books/tutorial/i18n/format/example-1dot1/NumberFormatDemo.java) displays numbers formatted for the French locale incorrectly.

--- begin code ---

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

public class NumberFormatDemo {

   static public void displayNumber(Locale currentLocale) {

      Integer quantity = new Integer(123456);
      Double amount = new Double(345987.246);
      NumberFormat numberFormatter;
      String quantityOut;
      String amountOut;

      numberFormatter = NumberFormat.getNumberInstance(currentLocale);
      quantityOut = numberFormatter.format(quantity);
      amountOut = numberFormatter.format(amount);
      System.out.println(quantityOut + "   " + currentLocale.toString());
      System.out.println(amountOut + "   " + currentLocale.toString());
   }

   static public void displayCurrency(Locale currentLocale) {

      Double currency = new Double(9876543.21);
      NumberFormat currencyFormatter;
      String currencyOut;

      currencyFormatter = NumberFormat.getCurrencyInstance(currentLocale);
      currencyOut = currencyFormatter.format(currency);
      System.out.println(currencyOut + "   " + currentLocale.toString());
   }

   static public void displayPercent(Locale currentLocale) {

      Double percent = new Double(0.75);
      NumberFormat percentFormatter;
      String percentOut;

      percentFormatter = NumberFormat.getPercentInstance(currentLocale);
      percentOut = percentFormatter.format(percent);
      System.out.println(percentOut + "   " + currentLocale.toString());
   }

   static public void main(String[] args) {

      Locale[] locales = {
          new Locale("fr","FR"),
          new Locale("de","DE"),
          new Locale("en","US")
      };

      for (int i = 0; i < locales.length; i++) {
         System.out.println();
         displayNumber(locales[i]);
         displayCurrency(locales[i]);
         displayPercent(locales[i]);
      }
   }

}

--- end code ---

This is part of the output using JDK 1.2.1 and 1.2.2 on Solaris:

123?456   fr_FR
345?987,246   fr_FR
9?876?543,21 F   fr_FR
75%   fr_FR

On Win32, the ?'s are replaced with a's with the grave accent ("`").

In the correct output, the ?'s should be spaces.

Comments
EVALUATION Is this really occurring on Solaris 2.5? And in which Solaris locale? So far, I can repro this only on Solaris 7 in the C locale, and there it doesn't surprise me. norbert.lindenberg@Eng 2000-03-13 This bug has been marked as incomplete but the person who submitted this bug is no longer at the company. There are also no comments in the Bug Parade to provide additional information. I am not sure what engineering would like to do with this bug by marking it as incomplete. sheri.good@Eng 2000-03-27 Then I'll assume it's the known problem with Solaris 7: On Solaris 7 with the C locale, the OS specifies "646" as the encoding, which translates to ASCII. With ASCII as the file encoding, the non-breaking space characters which are used as thousands separators map to '?'. norbert.lindenberg@Eng 2000-04-06 It's not a problem of Solaris 7, either. In the POSIX and XPG standards, the C locale is strictly defined. Portable Character Set (PCS) is defined for the C locale. No other characters than PCS are defined for the C locale. PCS is strictly a character set definition, not an encoding definition. So, it's possible to implement the C locale with any encoding that includes all of the PCS characters. Solaris implements the C locale using ASCII. Therefore, returning "646" by nl_langinfo(CODESET) in the C locale is correct. (I personally prefer a more descriptive name, though.) Again, any characters outside ASCII are not defined in the C locale. Therefore, mapping "646" to "ASCII" in Java is correct. Unless the single bytes, 0x80 to 0xff, are defined as a character, it's not possible to map to Unicode. masayoshi.okutsu@Eng 2000-04-07
07-04-2000