• Log in or sign up for an account here: https://www.sythe.org/login

Help Integer.parseInt

Morphis

Apprentice
Joined
Aug 2, 2008
Sythe Gold
0
Messages
734
Help Integer.parseInt
Well I am trying to convert a string to an int. The string grabs numbers from a website, and then i convert the string to an int that I can use to do calculations. My question is this, how can I convert a string with a comma to an int. I am getting an error when the number exceeds 3 digits and the website adds a comma.

For example the website has a number - 1,487

The string grabs that all good and it will return 1,487 but when i do
Code:
int x = Integer.parseInt(string);
I get an error because of the damn comma.

Any help is greatly appreciated.
 
Help Integer.parseInt
Nevermind, thanks I got it now I think. When I get home ill try this out
Code:
String newString = oldString.replace(",","");

you think that will work?
 
Help Integer.parseInt
It should do the trick although I don't recall ever trying the replace function with a blank string ("") parameter.
 
Help Integer.parseInt
Ya this is my first time even using it, and it works removes the commas, i later replace them with Number Formatting.
 
Help Integer.parseInt
If the replace function does not work then you could always convert it to a char array and then loop through it and shift everything left when the loop encounters a comma. Not the best solution but certainly an option should all others fail.
 
Runescape Gamblingrunescape gambling
Back
Top