hello,
Is this a bug in DecimalFormat, or that I am not using it correctly?
this is my code:
public static void main(String[] args)
{
// create German Locale
Locale locale = new Locale("de");
DecimalFormat format1 =
(DecimalFormat)DecimalFormat.getInstance(locale);
try {
DecimalFormat format2 = new
DecimalFormat(format1.toLocalizedPattern());
}
catch(Exception e) {
System.out.print(e);
}
and I get this Exception:
java.lang.IllegalArgumentException: Malformed pattern "#.##0,###"
I will really appriciate any help on this.
Thanks,
Asaf
Roedy Green - 19 Oct 2005 14:05 GMT
>java.lang.IllegalArgumentException: Malformed pattern "#.##0,###"
You write the patterns as if you were in North America. Then if you
are in Sweden it will reverse the decimal and comma on use.
You would thus write that pattern as "#,##0.###"

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
Oliver Wong - 19 Oct 2005 18:36 GMT
> hello,
>
[quoted text clipped - 19 lines]
>
> I will really appriciate any help on this.
From the Javadocs for the constructor DecimalFormat(string):
<javadoc>
Creates a DecimalFormat using the given pattern and the symbols for the
default locale.
</javadoc>
Therefore, the constructor expects the pattern to be in the default
locale, but you've supplied a pattern in the German locale, which is why
it's confused.
- Oliver