Using Java’s Float class.

float f = Float.parseFloat("25");
String s = Float.toString(25.0f);

To compare it's always better to convert the string to float and compare as two floats. This is because for one float number there are multiple string representations, which are different when compared as strings (e.g. "25" != "25.0" != "25.00" etc.)

Answer from Petar Ivanov on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-convert-a-string-value-to-float-value-in-java-with-examples
Convert String to Float in Java - GeeksforGeeks
July 12, 2025 - ... // Java program to convert String to float import java.util.*; public class StringToFloat { public static void main(String[] args) { String s = "1.6"; // Convert string to float float n = Float.parseFloat(s); System.out.println("" + n); } }
🌐
Baeldung
baeldung.com › home › java › java string › convert string to float and back in java
Convert String to Float and Back in Java | Baeldung
January 8, 2024 - One of the most common ways is to use Float‘s static method: parseFloat(). It will return a primitive float value, represented by the String argument.
🌐
Scaler
scaler.com › home › topics › string to float in java
String to Float in Java - Scaler Topics
May 31, 2022 - In the above example, we used the DecimalFormat class to convert string to float. We first created an instance df of this class. Then, we parsed the string value into the instance df and used the floatValue() method to convert the string into float.
🌐
Javatpoint
javatpoint.com › java-string-to-float
Java String to float - Javatpoint
Java Convert String to float example and examples of string to int, int to string, string to date, date to string, string to long, long to string, string to char, char to string, int to long, long to int etc.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Float.html
Float (Java Platform SE 8 )
October 20, 2025 - In general, the two-step sequence ... converted to an intermediate double and then to float, the string "1.00000017881393421514957253748434595763683319091796875001d" results in the float value 1.0000002f; if the string is converted directly to float, 1.0000001f resu...
🌐
TutorialsPoint
tutorialspoint.com › convert-from-string-to-float-in-java
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.
🌐
Java67
java67.com › 2015 › 05 › how-to-convert-string-to-float-in-java.html
How to convert String to Float in Java and vice-versa - Tutorial | Java67
You can also see Core Java Volume 1 - Fundamentals by Cay S. Horstmann to learn more about different static factory methods to convert one type of variable to another primitive or wrapper type in Java. BTW, if you already have Float object then you don't need to do String concatenation because calling Float.toString() will anyway give you floating point String you are looking for.
Find elsewhere
🌐
Blogger
javarevisited.blogspot.com › 2013 › 08 › how-to-parse-string-to-float-in-java-to-float-example.html
3 ways to parse String to float in Java? Examples
If you are already familiar with converting String to int or maybe String to double in Java, then you can extend the same techniques and method to parse float String values. key methods like valueOf() and parseInt(), which is used to parse String to float are overloaded for most primitive data types. If you are particularly interested in rounding of float values, you can use RoundingMode and BigDecimal class, as float and double are always approximate values, and comparing two float variables of the same values may not always return true, that's why it's advised, not to use float for monetary calculation. In this Java tutorial, we will first see examples of parsing String to float in Java and later converting float to String objects.
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › lang › Float.html
Float (Java SE 17 & JDK 17)
January 20, 2026 - In general, the two-step sequence ... converted to an intermediate double and then to float, the string "1.00000017881393421514957253748434595763683319091796875001d" results in the float value 1.0000002f; if the string is converted directly to float, 1.0000001f resu...
🌐
Tutorjoes
tutorjoes.in › Java_example_programs › convert_string_to_float_in_java
Write Java program to Convert String to Float
Enter the Float Value : 84.45371 String Value : 84.45371 Float Value Using floatValue() Method : 84.45371 Float Value Using parseFloat() Method : 84.45371
🌐
Java Guides
javaguides.net › 2018 › 08 › java-convert-string-to-float-example.html
Convert String To Float in Java
June 15, 2024 - The DecimalFormat class allows ... StringToFloatUsingDecimalFormat { public static void main(String[] args) { String strValue = "1234.56"; // Convert string to float using DecimalFormat DecimalFormat decimalFormat = new ...
🌐
Makeinjava
makeinjava.com › home › program to convert string to float in java (example)
Program to convert String to Float in java (example)
January 4, 2024 - String-to-float conversion ensures accurate representation of smaller decimal values, enabling these applications to operate swiftly and effectively. Java offers a method, Float.parseFloat(), specifically designed to convert strings containing numeric representations into their float counterparts.
🌐
EDUCBA
educba.com › home › software development › software development tutorials › java tutorial › java string to float
Java String to Float | Simple Ways To Convert String to Float in Java
March 27, 2023 - This example shows how to use the parseFloat() method to convert string to float.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Alvin Alexander
alvinalexander.com › java › edu › qanda › pjqa00013.shtml
How to convert a Java String to a float | alvinalexander.com
public class StringToFloat { public ... (NumberFormatException nfe) { System.out.println("NumberFormatException: " + nfe.getMessage()); } } } Float.toString(float f) is used to convert in the other direction, from a float to a String....
🌐
Oracle
docs.oracle.com › en › java › javase › 21 › docs › api › java.base › java › lang › Float.html
Float (Java SE 21 & JDK 21)
October 20, 2025 - In general, the two-step sequence ... converted to an intermediate double and then to float, the string "1.00000017881393421514957253748434595763683319091796875001d" results in the float value 1.0000002f; if the string is converted directly to float, 1.0000001f resu...
🌐
Tutorial Gateway
tutorialgateway.org › home › java programs › java program to convert string to float
Java Program to Convert String to Float
January 22, 2025 - public class stringToFloat { public static void main(String[] args) { String s1 = "10.22F"; String s2 = "33.21F"; float f1 = Float.parseFloat(s1); float f2 = Float.parseFloat(s2); System.out.println("Float.parseFloat(s1) result = " + f1); ...
🌐
Studytonight
studytonight.com › java-type-conversion › how-to-convert-java-string-to-float
How to convert Java String to float - Studytonight
Here, a string value is converted into the float values by using the parseFloat() method. public class StudyTonight { public static void main(String args[]) { String s = "454.86"; //String Decleration float i = Float.parseFloat(s); // ...