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
🌐
GUVI
guvi.in › hub › java-type-conversion-tutorial › string-to-float
How to Convert String to float in Java?
Our team will reach you out within the next 24 hours.Explore all Programs ... In Java, a String can be converted into a float value by using the Float.parseFloat() method and by using the Float.valueOf() method.
🌐
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.
Discussions

Convert float to String and String to float in Java - Stack Overflow
How could I convert from float to string or string to float? In my case I need to make the assertion between 2 values string (value that I have got from table) and float value that I have calculated. More on stackoverflow.com
🌐 stackoverflow.com
How to convert String to a float? I know for new Float( ) or Float.parseFloat( ) or Float.valueOf( ) tricks, but they don't work.
Float.parseFloat() or Float.valueOf() should work. You'll get a NumberFormatException if the string can't be parsed. From the exception you've posted it looks like you're trying to cast a Float to a String instead of using one of those methods. More on reddit.com
🌐 r/javahelp
13
0
January 13, 2020
converting string to float....
hi, am tryin o read a file and it has datas like as below 6.84464E-03 1.73275E-03 5.26343E-03 1.91723E-02 2.62422E-02 1.72165E-02 5.14687E-03 3.57361E-03 5.69188E-03-5.09780E-03-2.50582E-02-3.34189E... More on forums.oracle.com
🌐 forums.oracle.com
June 11, 2007
Simple and clean java float to string conversion - Stack Overflow
This is a very simple question, but I'm amazed on how difficult it has been to answer. Even the documentation didn't give a clear and straight answer. You see, I'm simply trying to convert a simple More on stackoverflow.com
🌐 stackoverflow.com
🌐
TutorialKart
tutorialkart.com › java › java-string-to-float
Convert String to Float in Java
January 9, 2023 - Float.parseFloat(str) parses any parsable float value from string to floating point value. In this example, we shall use Float.parseFloat() method and pass a string that is a parsable float value.
🌐
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 = ...
🌐
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.
How to convert String to a float? I know for new ...
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.

Find elsewhere
🌐
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)
November 18, 2009 - 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.
🌐
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.*; class GFG { // Function to convert String to Float public static float StringToFloat(String s) { // Convert string to float // using valueOf() method return Float.valueOf(s); ...
🌐
Oracle
forums.oracle.com › ords › apexds › post › converting-string-to-float-1237
converting string to float....
June 11, 2007 - hi, am tryin o read a file and it has datas like as below 6.84464E-03 1.73275E-03 5.26343E-03 1.91723E-02 2.62422E-02 1.72165E-02 5.14687E-03 3.57361E-03 5.69188E-03-5.09780E-03-2.50582E-02-3.34189E...
🌐
TutorialsPoint
tutorialspoint.com › java-program-to-convert-a-string-to-a-float-type-number
Java Program to convert a String to a float type Number
January 23, 2025 - The Float.parseFloat() method belongs to the Float class in Java and is used to convert a string representation of a number into a primitive float.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-program-to-convert-a-float-value-to-string
Java Program to Convert a Float value to String - GeeksforGeeks
July 12, 2025 - Strings - Strings in Java are objects that are supported internally by a char array. Since arrays are immutable, and strings are also a type of exceptional array that holds characters, therefore, strings are immutable as well. Float - The float data type is a single-precision 32-bit IEEE 754 floating-point. Its value range is unlimited. Using a float (instead of double) is suggested if you need to save memory in large arrays of floating-point numbers.
🌐
Python Examples
pythonexamples.org › java › how-to-convert-string-to-float
How to convert String to Float in Java
Finally, we print the float value float1 to the console. // Convert "3.14" String to Float public class Main { public static void main(String[] args) { String str1 = "3.14"; float float1 = Float.parseFloat(str1); System.out.println("Float value is: " + float1); } }
🌐
Codewithz
codewithz.com › category › java › section › core-java-programs › blog › java-program-to-convert-string-to-primitive-float
Java Program to convert String to Primitive Float
April 22, 2024 - Make sure to subscribe to our newsletter and be the first to know the news. ... Sending a mail using Java Code.
🌐
W3Schools
w3schools.com › java › java_data_types.asp
Java Data Types
assert abstract boolean break byte case catch char class continue default do double else enum exports extends final finally float for if implements import instanceof int interface long module native new package private protected public return requires short static super switch synchronized this throw throws transient try var void volatile while Java String Methods
🌐
W3Schools
w3schools.com › java › java_type_casting.asp
Java Type Casting
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate ... Type casting means converting one data type into another. For example, turning an int into a double. ... Widening Casting (automatic) - converting a smaller type to a larger type size byte -> short -> char -> int -> long -> float -> double
🌐
Studytonight
studytonight.com › java-type-conversion › how-to-convert-java-float-to-string
How to convert Java float to String - Studytonight
Here, a float value is passed in the method and converted into a String formatted up to 2 digits. import java.text.DecimalFormat; public class StudyTonight { public static void main(String args[]) { float n = 500.0878f; Float f = (float)n; String s = new DecimalFormat ("#.00").format (f); //for two places decimal System.out.println("String is : "+s); } }