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

NumberFormat instance for French locale displays funny characters

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.2.2
    • core-libs
    • None
    • sparc
    • solaris_2.5

      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.

            nlindenbsunw Norbert Lindenberg (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: