Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java Language
Expertise: Beginner
Jun 9, 1997

Parse string to float or double

Question:
Is there a command Float.parseNumbers(s) that returns a float?

Answer:
Sure, parseInt(s) is simply:

 Integer temp = Integer.valueOf(s);
   int x = temp.intValue();
which has an equivalent for floats
Float temp = Float.valueOf(s);
   float x = temp.floatValue();
which can be written as a single line
float x = Float.valueOf(s).floatValue();
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date