Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

DecimalFormat with Locale problem

Thread view: 
asafshec - 19 Oct 2005 13:22 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.