• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to covert a number in string form to float

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, thanks for the tip!
reply
    Bookmark Topic Watch Topic
  • New Topic