Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Formating number-Inputs by locale

 
Ben Klug
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ben Klug
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NumberFormat has a parse(String) method as well as format(int). Check the API.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic