• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cast number with comma as Integer.

 
Viidhya Kishore
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51344
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using the String methods which remove characters, then parse to an int.
 
Viidhya Kishore
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12263
36
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Viidhya Kishore
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. Thanks for your help.
Clients have such wierd requests.

 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ vidhya

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

 
fred rosenberger
lowercase baba
Bartender
Posts: 12263
36
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:
Assuming there IS a database...


oops i missed it ... thanks fred for pointing out ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic