The float value at that high value has a precision of only 0.5, so Java parsed it to the closest float value it could = 5555998.5, and that's what was printed.

To see the difference between the 2 closest values at that magnitude, use Math.ulp (unit in the last place):

String s = "5555998.558f";
float value = Float.parseFloat(s);
System.out.println(value);
System.out.println(Math.ulp(value));

This prints

5555998.5
0.5

You can use a double which has much better precision:

double d = Double.parseDouble(s);
System.out.println(d);
System.out.println(Math.ulp(d));

This prints

5555998.558
9.313225746154785E-10

Interestingly, Double.parseDouble doesn't seem to mind the f on the end. Double.parseDouble converts the String into a double "as performed by the valueOf method of class Double". And Double.valueOf states:

FloatValue:

  • Signopt NaN

  • Signopt Infinity

  • Signopt FloatingPointLiteral

  • Signopt HexFloatingPointLiteral

  • SignedInteger

This method will take a String as if it were a Java numeric literal, which Java supports with a f on the end to indicate a floating-point literal.

Answer from rgettman on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › float-parsefloat-method-in-java-with-examples
Float parseFloat() method in Java with examples - GeeksforGeeks
July 11, 2025 - // Java Code to implement // parseFloat() method of Float class class GFG { // Driver method public static void main(String[] args) { try { String str = ""; // returns the float value // represented by the string argument float val = Float.parseFloat(str); // prints the float value System.out.println("Value = " + val); } catch (Exception e) { System.out.println("Exception: " + e); } } }
🌐
Tutorialspoint
tutorialspoint.com › home › java/lang › java float parsefloat method
Java Float parseFloat Method
September 1, 2008 - The Java Float parseFloat(String s) method returns a new float initialized to the value represented by the specified String, as performed by the valueOf method of class Float.
🌐
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.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Float.html
Float (Java Platform SE 8 )
October 20, 2025 - public static float parseFloat(String s) throws NumberFormatException · Returns a new float initialized to the value represented by the specified String, as performed by the valueOf method of class Float. Parameters: s - the string to be parsed. Returns: the float value represented by the ...
🌐
LabEx
labex.io › tutorials › java-java-float-parsefloat-method-117680
Mastering Java's parseFloat Method | LabEx
In this lab, you learned how to use the parseFloat() method to parse a string value to its equivalent float value in Java programming.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.lang.float.parsefloat
Float.ParseFloat(String) Method (Java.Lang) | Microsoft Learn
Returns a new float initialized to the value represented by the specified String, as performed by the valueOf method of class Float. Added in 1.2. Java documentation for java.lang.Float.parseFloat(java.lang.String).
🌐
Scaler
scaler.com › home › topics › string to float in java
String to Float in Java - Scaler Topics
May 31, 2022 - The valueOf() method is a static method in the java.lang.Float class that is used to convert string to float in java. It accepts a string as input and converts it to a float value.
Find elsewhere
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › lang › Float.html
Float (Java Platform SE 7 )
public static float parseFloat(String s) throws NumberFormatException · Returns a new float initialized to the value represented by the specified String, as performed by the valueOf method of class Float. Parameters: s - the string to be parsed. Returns: the float value represented by the ...
🌐
Java Tutorial HQ
javatutorialhq.com › java tutorial › java.lang › float › java float parsefloat() method example
Java Float parseFloat() method example
September 30, 2019 - The method parseFloat(String s) just parse the String input s and eventually return a Float object. As you would have noticed, the String method argument should be a number which means it should be consists by our counting numbers.
🌐
IncludeHelp
includehelp.com › java › float-class-parsefloat-method-with-example.aspx
Java - Float Class parseFloat() Method
public static float parseFloat (String str); String str – represents the string value to be parsed. The return type of this method is float, it returns the corresponding float value that represent the String value. // Java program to demonstrate the example // of parseFloat(String str) method ...
🌐
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 - parseFloat · (String s) Returns a new float initialized to the value represented by the specified String, as performed by the valueOf method of class Float. Float · resolveConstantDesc · (MethodHandles.Lookup lookup) Resolves this instance as a ConstantDesc, the result of which is the instance ...
🌐
Globalyzer
globalyzer.com › gzserver › help › reference › localeSensitiveMethods › javaunsafe_parseFloat.html
parseFloat - Globalyzer Internationalization Help
public static float parseFloat(String s) · The parseFloat method returns a float primitive value by parsing a floating point string
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.base › java › lang › Float.html
Float (Java SE 11 & JDK 11 )
January 20, 2026 - public static float parseFloat​(String s) throws NumberFormatException · Returns a new float initialized to the value represented by the specified String, as performed by the valueOf method of class Float. Parameters: s - the string to be parsed. Returns: the float value represented by the ...
🌐
W3Schools
w3schools.com › jsref › jsref_parsefloat.asp
JavaScript parseFloat() Method
parseFloat("40.00"); parseFloat(" 40 "); parseFloat("40 years"); parseFloat("40H") parseFloat("H40"); Try it Yourself » ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
🌐
Coderanch
coderanch.com › t › 403330 › java › Float-parseFloat-string-accurate-conversion
Float.parseFloat(string) not accurate conversion (Beginning Java forum at Coderanch)
String s=5555.6789, Float.parseFloat(s)=5555.6787, Float.valueOf(s)=5555.6787 <=== Note 7 at the end? String s=5555.67898898098989797987987987987, Float.parseFloat(s)=5555.679, Float.valueOf(s)=5555.679 <== why only 3 digit at the end ?
🌐
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
* * @author WINDOWS 8 */ public class Test { public static void main(String args[]){ // let's first learn how to convert String to float in Java String decimal = "100.25"; // first we can use parseFloat() method to convert String to Float float f = Float.parseFloat(decimal); System.out.println("float equvialent of String " + decimal + " is : " + f); // remember it's not necessary that String always has floating point // so this is also Ok f = Float.parseFloat("200"); System.out.println("String 200 in float is : " + f); // another way to convert String to float is by using // valueOf() method S
🌐
Studytonight
studytonight.com › java-wrapper-class › java-float-parsefloat-method
Java Float parseFloat() Method - Studytonight
Java parseFloat() method is the part of the Float class of the java.lang package. This method is used to parse the string value to its equivalent float value.