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 OverflowGeeksforGeeks
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); } }
Top answer 1 of 10
407
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.)
2 of 10
37
Float to string - String.valueOf()
float amount=100.00f;
String strAmount=String.valueOf(amount);
// or Float.toString(float)
String to Float - Float.parseFloat()
String strAmount="100.20";
float amount=Float.parseFloat(strAmount)
// or Float.valueOf(string)
Videos
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.
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.
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.
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...
Alvin Alexander
alvinalexander.com › blog › post › java › convert-string-float
Java String to float conversion example | alvinalexander.com
This example code segment converts the String "100.00" to a Java float:
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
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.
Naukri
naukri.com › code360 › library › how-to-convert-string-to-float-in-java
Convert String to Float in Java - Naukri Code 360
Almost there... just a few more seconds
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
Call +917738666252
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...