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 int formatting??? 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 "int formatting???" Watch "int formatting???" New topic
Author

int formatting???

Kate Zoy
Ranch Hand

Joined: Feb 11, 2004
Posts: 33
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!
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
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.


Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: int formatting???
 
Similar Threads
Unpredicatable rounding decimals using Number Format/ Decimal Format
String formatting question
Formatting integers - should be easy?!
number formatting????
Numberformater or substring or ????