This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Formating number-Inputs by locale Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Formating number-Inputs by locale" Watch "Formating number-Inputs by locale" New topic
Author

Formating number-Inputs by locale

Ben Klug
Ranch Hand

Joined: Jan 28, 2002
Posts: 45
Hello,
does anybody know how to format numbers entered in a locale-Format. eg for Germany I enter the number 1.5 like 1,5
I know the Locale of the User! How can I solve this??
thnx
B
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Ben,
Something like this will do it for you:

You can specify a locale usig one of the constants in the Locale class as an argument to the getInstance method, like this:
NumberFormat currFormat = NumberFormat.getInstance(Locale.GERMANY);
hope that helps


Dave
Ben Klug
Ranch Hand

Joined: Jan 28, 2002
Posts: 45
Hello Dave,
sorry, my description was not very clear. I need it the other way round. What I have is a String like "1,23" and I want to transform that into a double value 1.23. Should wor for all locales.
Thankyou
Ben
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
NumberFormat has a parse(String) method as well as format(int). Check the API.


"I'm not back." - Bill Harding, Twister
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Formating number-Inputs by locale