-
Bug
-
Resolution: Fixed
-
P3
-
6
-
b24
-
sparc
-
solaris_8
When using the DecimalFormat.format or DecimalFormat.toPattern() API
depending a given locale (default is OS locale). The JVM 1.4.1_05 or 1.4.2_04-b05 has the wrong
format. Either the comma and period are the reverse of what they should be
or the currency symbol is wrong. For example when using the code (attached to this email)
------------------------------------------------------------
import java.util.*;
import java.text.*;
public class localeDisplay {
static public void localizedFormat(String pattern, double value, Locale
loc ) {
NumberFormat nf = NumberFormat.getCurrencyInstance(loc);
DecimalFormat df = (DecimalFormat)nf;
df.applyPattern(pattern);
String output1 = "DecimalFormat.format("+value+")="+df.format(value);
String output2 = "DecimalFormat.toPattern()="+df.toPattern();
System.out.println("----------");
System.out.println("Pattern=" + pattern + " " + output1 + " " +
output2 + " " + loc.toString());
}
static public void main(String[] args) {
Locale[] locales = {
new Locale("en", "US"),
new Locale("en", "GB"),
new Locale("de", "DE"),
new Locale("fr", "FR"),
new Locale("fr", "HT"),
new Locale("pt", "BR"),
new Locale("pt", "PT"),
new Locale("es", "CO"),
new Locale("es", "ES"),
new Locale("es", "BO"),
new Locale("es", "AR"),
new Locale("es", "EC"),
new Locale("es", "MX"),
};
for (int i = 0; i < locales.length; i++) {
localizedFormat("\u00A4###,###.###", 123456.789, locales[i]);
}
}
}
------------------------------------------------------------
The output is:
------------------------------------------------------------
Pattern=±###,###.### DecimalFormat.format(123456.789)=$123,456.789
DecimalFormat.toPattern()=±#,##0.### en_US
----------
Pattern=±###,###.### DecimalFormat.format(123456.789)=M-^T123,456.789
DecimalFormat.toPattern()=±#,##0.### en_GB
----------
Pattern=±###,###.### DecimalFormat.format(123456.789)=Ì123.456,789
DecimalFormat.toPattern()=±#,##0.### de_DE
----------
Pattern=±###,###.### DecimalFormat.format(123456.789)=Ì123ß456,789
DecimalFormat.toPattern()=±#,##0.### fr_FR
----------
Pattern=±###,###.### DecimalFormat.format(123456.789)=HTG123ß456,789
DecimalFormat.toPattern()=±#,##0.### fr_HT
----------
Pattern=±###,###.### DecimalFormat.format(123456.789)=R$123.456,789
DecimalFormat.toPattern()=±#,##0.### pt_BR
----------
Pattern=±###,###.### DecimalFormat.format(123456.789)=Ì123.456,789
DecimalFormat.toPattern()=±#,##0.### pt_PT
----------
Pattern=±###,###.### DecimalFormat.format(123456.789)=C$123,456.789
DecimalFormat.toPattern()=±#,##0.### es_CO
----------
Pattern=±###,###.### DecimalFormat.format(123456.789)=Ì123.456,789
DecimalFormat.toPattern()=±#,##0.### es_ES
----------
Pattern=±###,###.### DecimalFormat.format(123456.789)=B$123,456.789
DecimalFormat.toPattern()=±#,##0.### es_BO
----------
Pattern=±###,###.### DecimalFormat.format(123456.789)=$123.456,789
DecimalFormat.toPattern()=±#,##0.### es_AR
----------
Pattern=±###,###.### DecimalFormat.format(123456.789)=USD123,456.789
DecimalFormat.toPattern()=±#,##0.### es_EC
----------
Pattern=±###,###.### DecimalFormat.format(123456.789)=$123,456.789
DecimalFormat.toPattern()=±#,##0.### es_MX
------------------------------------------------------------
These locales can be verified against an international list of currency
symbols like:
(http://www.nationmaster.com/red/graph-T/cur_sym&;int=-1)
The way the comma and period are used in the representation of currency of
each country can be double-checked when looking at the UN page with links to
the website of each country's government:
http://www.un.org/esa/national.htm
So far the use of the comma and period in the currency is inversed and thus
wrong for all Latin American countries except Brazil and Mexico.
http://www.un.org/esa/govlatin.htm
This link is usesful -
http://www.microsoft.com/globaldev/nlsweb/default.asp
For example, for Ecuador and Columbia the format should be - 123.456,789
But the JVM gives 123,456.789
###@###.### 10/11/04 13:19 GMT
depending a given locale (default is OS locale). The JVM 1.4.1_05 or 1.4.2_04-b05 has the wrong
format. Either the comma and period are the reverse of what they should be
or the currency symbol is wrong. For example when using the code (attached to this email)
------------------------------------------------------------
import java.util.*;
import java.text.*;
public class localeDisplay {
static public void localizedFormat(String pattern, double value, Locale
loc ) {
NumberFormat nf = NumberFormat.getCurrencyInstance(loc);
DecimalFormat df = (DecimalFormat)nf;
df.applyPattern(pattern);
String output1 = "DecimalFormat.format("+value+")="+df.format(value);
String output2 = "DecimalFormat.toPattern()="+df.toPattern();
System.out.println("----------");
System.out.println("Pattern=" + pattern + " " + output1 + " " +
output2 + " " + loc.toString());
}
static public void main(String[] args) {
Locale[] locales = {
new Locale("en", "US"),
new Locale("en", "GB"),
new Locale("de", "DE"),
new Locale("fr", "FR"),
new Locale("fr", "HT"),
new Locale("pt", "BR"),
new Locale("pt", "PT"),
new Locale("es", "CO"),
new Locale("es", "ES"),
new Locale("es", "BO"),
new Locale("es", "AR"),
new Locale("es", "EC"),
new Locale("es", "MX"),
};
for (int i = 0; i < locales.length; i++) {
localizedFormat("\u00A4###,###.###", 123456.789, locales[i]);
}
}
}
------------------------------------------------------------
The output is:
------------------------------------------------------------
Pattern=±###,###.### DecimalFormat.format(123456.789)=$123,456.789
DecimalFormat.toPattern()=±#,##0.### en_US
----------
Pattern=±###,###.### DecimalFormat.format(123456.789)=M-^T123,456.789
DecimalFormat.toPattern()=±#,##0.### en_GB
----------
Pattern=±###,###.### DecimalFormat.format(123456.789)=Ì123.456,789
DecimalFormat.toPattern()=±#,##0.### de_DE
----------
Pattern=±###,###.### DecimalFormat.format(123456.789)=Ì123ß456,789
DecimalFormat.toPattern()=±#,##0.### fr_FR
----------
Pattern=±###,###.### DecimalFormat.format(123456.789)=HTG123ß456,789
DecimalFormat.toPattern()=±#,##0.### fr_HT
----------
Pattern=±###,###.### DecimalFormat.format(123456.789)=R$123.456,789
DecimalFormat.toPattern()=±#,##0.### pt_BR
----------
Pattern=±###,###.### DecimalFormat.format(123456.789)=Ì123.456,789
DecimalFormat.toPattern()=±#,##0.### pt_PT
----------
Pattern=±###,###.### DecimalFormat.format(123456.789)=C$123,456.789
DecimalFormat.toPattern()=±#,##0.### es_CO
----------
Pattern=±###,###.### DecimalFormat.format(123456.789)=Ì123.456,789
DecimalFormat.toPattern()=±#,##0.### es_ES
----------
Pattern=±###,###.### DecimalFormat.format(123456.789)=B$123,456.789
DecimalFormat.toPattern()=±#,##0.### es_BO
----------
Pattern=±###,###.### DecimalFormat.format(123456.789)=$123.456,789
DecimalFormat.toPattern()=±#,##0.### es_AR
----------
Pattern=±###,###.### DecimalFormat.format(123456.789)=USD123,456.789
DecimalFormat.toPattern()=±#,##0.### es_EC
----------
Pattern=±###,###.### DecimalFormat.format(123456.789)=$123,456.789
DecimalFormat.toPattern()=±#,##0.### es_MX
------------------------------------------------------------
These locales can be verified against an international list of currency
symbols like:
(http://www.nationmaster.com/red/graph-T/cur_sym&;int=-1)
The way the comma and period are used in the representation of currency of
each country can be double-checked when looking at the UN page with links to
the website of each country's government:
http://www.un.org/esa/national.htm
So far the use of the comma and period in the currency is inversed and thus
wrong for all Latin American countries except Brazil and Mexico.
http://www.un.org/esa/govlatin.htm
This link is usesful -
http://www.microsoft.com/globaldev/nlsweb/default.asp
For example, for Ecuador and Columbia the format should be - 123.456,789
But the JVM gives 123,456.789
###@###.### 10/11/04 13:19 GMT