aspose file tools*
The moose likes Beginning Java and the fly likes Cast number with comma as Integer. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Cast number with comma as Integer." Watch "Cast number with comma as Integer." New topic
Author

Cast number with comma as Integer.

Viidhya Kishore
Ranch Hand

Joined: Jan 03, 2007
Posts: 99
Hello,
I am formatting an Object which is a number into a comma pattern.
Eg the number is 12345678.
I apply comma pattern and format it to 123,45,678 using
DecimalFormat df = (DecimalFormat) nf;
df.applyPattern(getPattern());
itemValue = df.format(itemValue);

Now the itemValue is of type String.
I would like to convert it into a Number but still have the commas.
Is it possible? Any help.
I need it as a number as I export to excel and the column has to be all numbers so they can be 'SUM' ed.

Please help.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38392
    
  23
Try using the String methods which remove characters, then parse to an int.
Viidhya Kishore
Ranch Hand

Joined: Jan 03, 2007
Posts: 99
But I want the commas too and still have the object as a number and not a string.
Is it possible?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11239
    
  16

You should separate out how you STORE it from how you DISPLAY it.

a number does not have commas in it. If you want to store something with commas in it, then you're not storing a number, you're storing a string.

If you want to store a string, then don't consider it as a number.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Viidhya Kishore
Ranch Hand

Joined: Jan 03, 2007
Posts: 99
Ok. Thanks for your help.
Clients have such wierd requests.

Lalit Mehra
Ranch Hand

Joined: Jun 08, 2010
Posts: 384

@ vidhya

Hi, you can do the same by qualifying the filters of the Number datatype in your database ...



http://plainoldjavaobject.blogspot.in
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11239
    
  16

Lalit Mehra wrote:@ vidhya

Hi, you can do the same by qualifying the filters of the Number datatype in your database ...


Assuming there IS a database...
Lalit Mehra
Ranch Hand

Joined: Jun 08, 2010
Posts: 384

fred rosenberger wrote:
Assuming there IS a database...


oops i missed it ... thanks fred for pointing out ...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cast number with comma as Integer.