- 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 string value to float using Float.valueOf()
The Float.valueOf() method is used in Java to convert string to float.
The following are our string values.
String str1 = "100.5"; String str2 = "200.5";
To convert the string value to float, try the method valueOf()
float val1 = (Float.valueOf(str1)).floatValue(); float val2 = (Float.valueOf(str2)).floatValue();
The following is the complete example with output.
Example
public class Demo { public static void main(String args[]) throws Exception { String str1 = "100.5"; String str2 = "200.5"; float val1 = (Float.valueOf(str1)).floatValue(); float val2 = (Float.valueOf(str2)).floatValue(); System.out.println("Multiplication = " + (val1 * val2)); } }
Output
Multiplication = 20150.25
Advertisements