• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

creating a method inserting commas correctly in a given number

 
Johnny Steele
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I'm creating a method that inserts commas in an integer given as an argument and returns it as a string with the commas inserted in the propor places. I have the following but does anyone have any ideas as to how I can do this without importing decimal format, like with toString or the like?


 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No you're doing it the right way. You could make your formatter private static final so that it won't need to create an instance of it every time the method is invoked.
 
Johnny Steele
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks! But how would I do the same thing without decimalFormat using toString?
 
Campbell Ritchie
Sheriff
Posts: 48374
56
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String#format??
If you use the , option on the %d tag, you can have commas inserted, but they only go in the conventional position for your Locale.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic