Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parseFloat?? parseDouble??

Status
Not open for further replies.

modalman

Programmer
Feb 14, 2001
156
0
0
GB
Hi. I have a string that contains delimited ints and floats and these are converted and read into an array. It works fine until a float appears, then I get the numberException error. I have tried casting etc but to no avail. I only need ints in the array so I'm not worried about the fractions, its just that parseInt doesn't seem to work if the string is a float. Any ideas? Many thanks in advance.

ASCII silly question, get a silly ANSI
 
Oops, here's the code:

int weightAr[] = new int[stringtokenizer.countTokens()];
for(int i = 0; i < weightAr.length-1; i++)
weightAr = (int)Integer.parseInt(stringtokenizer.nextToken());



ASCII silly question, get a silly ANSI
 
Yeah, its a bit naff isn't it. Try this :

String s = "1.023513515";
int i = (int)Double.parseDouble(s);
 
PS, this will work whether your input is "123" or "123.54654
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top