String to Float (Very important)

How can I convet a String to a float?

feupAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
omokConnect With a Mentor Commented:
String floatStr = "1.234";
float floatValue = (new Float(floatStr)).floatValue();
OR
float floatValue = Float.valueOf(floatStr).floatValue();
0
 
diakovCommented:
Just a remark. Since you say 'important' you also have to put the suggested expression in a try ... catch block to process possible conversion exceptions. Also Float provides some means for testing for the special float numbers like infinity, nan, etc.

Cheers.
0
 
feupAuthor Commented:
Thank you very much. You just helped me finishing my project in the university.

Thanx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.