wood burning stoves
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Formating number-Inputs by locale" Watch "Formating number-Inputs by locale" New topic

Formating number-Inputs by locale

Ben Klug
Ranch Hand

Joined: Jan 28, 2002
Posts: 45
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??
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
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

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.
Jim Yingst

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
I agree. Here's the link: http://aspose.com/file-tools
subject: Formating number-Inputs by locale
It's not a secret anymore!