• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to covert a number in string form to float

 
Amir Abbas
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
plz help me How to covert a number in string form to float form Thanx in advance
Amir
hi_amir@hotmail.com (for msn)
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Welcome to JavaRanch.
The short answer is:
String string = "123";
int number = Integer.parseInt(string);
or
String string = "123.45";
double number = Double.parseDouble(string);
If you'd like more information on the subject, I recommend doing a search on the beginner's forum. The link to the search page is at the top-right of this page.
Good Luck.
 
Amir Abbas
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had tried the float one method which you tell but it give error
i have jdk1.3
plz help
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you use
String string = "123";
int number = Integer.parseInt(string);
String string = "123.45";
double number = Double.parseDouble(string);
in the same scope?
Just use different variables and it should work fine.
-anthony
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amir,
If you are still having difficulties, it may be useful if you were to post the code you are trying to compile as well as the error messages you are receiving.
Note: When posting code, please enclose it with the [ code ] and [ /code ] tags (click on the "CODE" button below the message posting textbox).
Good Luck.
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, thanks for the tip!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic