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); } }
🌐
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
Java designer knows about that and they have made arrangement to carry out this basic task in a predictable and consistent manner. Once you know the trick to convert String to float, you should be able to convert String to Integer, Double, and Short. BTW, converting String to a byte array is a little bit tricky because String is text data and bytes are binary, so character encoding comes into the picture.
🌐
Scaler
scaler.com › home › topics › string to float in java
String to Float in Java - Scaler Topics
May 31, 2022 - The parseFloat() method is a static method of Float class used to convert string to float in java. It takes the string to be parsed as its input and returns the float type of the string.
🌐
Reddit
reddit.com › r/javahelp › how to convert string to a float? i know for new float( ) or float.parsefloat( ) or float.valueof( ) tricks, but they don't work.
r/javahelp on Reddit: How to convert String to a float? I know for new Float( ) or Float.parseFloat( ) or Float.valueOf( ) tricks, but they don't work.
January 13, 2020 -

I need to put a String in sePrice(float price) setter, but then I get this error: Exception in thread "JavaFX Application Thread" java.lang.ClassCastException: class java.lang.Float cannot be cast to class java.lang.String (java.lang.Float and java.lang.String are in module java.

public class Product {
private SimpleStringProperty name;
private SimpleFloatProperty price;

//I need to to a String here from another method and then convert it to a float.

public void setPrice(float price) {
this.price.set(price);
}
}

I need to use SimpleFloatProperty because I use TableVIew.

🌐
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.
Find elsewhere
🌐
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 - Java™ Platform Standard Ed. 8 ... The Float class wraps a value of primitive type float in an object. An object of type Float contains a single field whose type is float. In addition, this class provides several methods for converting a float to a String and a String to a float, as well as ...
🌐
BeginnersBook
beginnersbook.com › 2022 › 11 › java-string-to-float-conversion
Java String to float Conversion
In such scenario, we can use the valueOf() method of Float class. This method expects the string to contain dot instead of comma so we need to call replace() method of String class to replace the comma with dot. public class JavaExample{ public static void main(String args[]){ String str = ...
🌐
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 - ... Deprecated, for removal: This API element is subject to removal in a future version. It is rarely appropriate to use this constructor. Use parseFloat(String) to convert a string to a float primitive, or use valueOf(String) to convert a string to a Float object.
🌐
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 - ... In the above method, first an instance of java.text.DecimalFormat is created, and then the parse method is involved accepting string as input type, then followed by the floatValue () method to get float value.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
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
Here is Java program to parse String to floating point number in Java and then convert back float to java.lang.String object. String to Float Conversion Example in Java. ... That's all on this Java beginner's tutorial about parsing String to float in Java and then converting back float values to String objects.
🌐
Coderanch
coderanch.com › t › 471633 › java › convert-String-float-exact-decimal
How to convert String to float with exact decimal value (Java in General forum at Coderanch)
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums · this forum made possible by our volunteer staff, including ... ... Hi, When I convert a String value to float by using Float.valueOf(String), The return value is not containing last decimal.
🌐
Scientech Easy
scientecheasy.com › home › blog › how to convert string to float in java
How to Convert String to Float in Java - Scientech Easy
February 2, 2025 - The floatValue() method converts the float object into primitive float type numeric value. This is called “unboxing” in Java. Unboxing is a process by which we convert an object into its corresponding primitive data type. Let’s create a Java program to convert String into a float object ...
🌐
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....
🌐
Studytonight
studytonight.com › java-type-conversion › how-to-convert-java-string-to-float
How to convert Java String to float - Studytonight
Compilers to execute code in browser. ... Learn Coding! ... In Java, a String can be converted into a float value by using the Float.parseFloat() method and by using the Float.valueOf() method.