Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

int formatting???

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have an int (unknown lenght) that i need to format so there's a comma every 3 digits, like "1,000,203,2203". I know about DecimalFormat df1 = new DecimalFormat(), but I'm not quite sure what to put in the parentheses. If I knew the int was 4 digits, I could do "0,000", but I'm not sure how to go about formatting an unknown number of digits. Let me know!
Thanks!
 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're on the right track, just use #'s instead of 0's in you DecimalFormatter, like this:
If the number is more than 6 digits, it will automatically stick in another "," at the right places so you don't have to guess at the size.
Try it out and you'll see what I mean.
 
reply
    Bookmark Topic Watch Topic
  • New Topic