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.
--- 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.
- relates to
-
JDK-4418200 Currency formatting for some locales produces question marks
-
- Closed
-