| 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: 32680
|
|
|
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: 9948
|
|
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.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
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: 369
|
|
@ 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: 9948
|
|
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: 369
|
|
fred rosenberger wrote:
Assuming there IS a database...
oops i missed it ... thanks fred for pointing out ...
|
 |
 |
|
|
subject: Cast number with comma as Integer.
|
|
|