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 formatting integer to include commas 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 "formatting integer to include commas" Watch "formatting integer to include commas" New topic

formatting integer to include commas

Bill Brasskey
Ranch Hand

Joined: Jun 01, 2004
Posts: 47
All I'm wanting to do is format an integer to include commas in the proper places... if I use NumberFormat class and set min and max fraction digits to "0" , will this work? I dont want the period at the end, either.
ex. 1000 to 1,000
Eric Fletcher
Ranch Hand

Joined: Oct 26, 2000
Posts: 188
Check out the API for DecimalFormat, it should help you out. Take a look.


My theory of evolution is that Darwin was adopted. - Steven Wright
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
Use DecimalFormat which is a concrete subclass of NumberFormat. You can use it to specify the exact mask you want to apply, like this:

I believe that will give you the result you are looking for.

Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
I agree. Here's the link:
subject: formatting integer to include commas
Similar Threads
Illegal format conversion exception for printf
numeric literals that include comma, beware of this
How to read CSV?
4b - input arg question
File reading