- 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
Java Program to convert a String to a float type Number
Use the parseFloat() method in Java to convert a String to a float type.
Let’s say we have the following string.
String str = "111.8";
Now, the Float.parseFloat() method will convert it to a float type number.
float floatVal = Float.parseFloat(str);
The following is the complete example with output.
Example
public class Demo { public static void main(String args[]) { String str = "111.8"; float floatVal = Float.parseFloat(str); System.out.println("Float: "+floatVal); } }
Output
Float: 111.8
Advertisements