This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android 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
 
Consider Paul's rocket mass heater.
 
subject: Formating number-Inputs by locale
 
Similar Threads
NumberFormat question
how can show Hongkong's currency?
API content Question
how to use locale in javascript
JasperReport Number Format problem