• Post Reply Bookmark Topic Watch Topic
  • New Topic

need help formatting numbers as strings  RSS feed

 
M Burke
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to format numbers that are represented as both as ints and doubles.

So String1 = "123123123.455"
I want to convert to "123,123,123.455"

And String2 = "123123123"
convert to "123,123,123"

What is the best way to do this? I played around with String.format, but I am not sure what the mask would look like.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use java.text.DecimalFormat.

 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use String.format, you want to look at the java.util.Formatter class, which has a list of possible tags. You will find a comma flag as well; that might help.
 
M Burke
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!