File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes creating a method inserting commas correctly in a given number Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "creating a method inserting commas correctly in a given number" Watch "creating a method inserting commas correctly in a given number" New topic
Author

creating a method inserting commas correctly in a given number

Johnny Steele
Greenhorn

Joined: Nov 12, 2010
Posts: 12
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?



el Duderino
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

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.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Johnny Steele
Greenhorn

Joined: Nov 12, 2010
Posts: 12
thanks! But how would I do the same thing without decimalFormat using toString?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: creating a method inserting commas correctly in a given number
 
Similar Threads
Rounding a float value upto 2 decimal places
help with double
DecimalFormat
Cast number with comma as Integer.
How to form a new string out of several old strings excluding some??.......