File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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
It's not a secret anymore!