- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert from String to float in Java
To convert String to float, use the valueOf() method.
Let’s say we have the following string value.
String str = "0.8";
Converting the string to float.
Float floatVal = Float.valueOf(str).floatValue();
The following is the complete example.
Example
public class Demo { public static void main(String args[]) { String str = "0.8"; Float floatVal = Float.valueOf(str).floatValue(); System.out.println("Float: "+floatVal); } }
Output
Float: 0.8
Advertisements