Just cast your double to a float.

Copydouble d = getInfoValueNumeric();
float f = (float)d;

Also notice that the primitive types can NOT store an infinite set of numbers:

Copyfloat range: from 1.40129846432481707e-45 to 3.40282346638528860e+38
double range: from 1.7e–308 to 1.7e+308
Answer from Tom Wellbrock on Stack Overflow
🌐
Baeldung
baeldung.com › home › java › java numbers › how to convert double to float in java
How to Convert Double to Float in Java | Baeldung
April 19, 2024 - Similarly to our first conversion example, we use a value of 0.0000001 for our delta. Next, let’s show how to convert float to double data types:
🌐
Java Code Geeks
examples.javacodegeeks.com › home › java development › core java
Convert Between Double and Float in Java - Java Code Geeks
March 18, 2024 - We’ll explore two techniques for converting between double and float data types in Java—Type Casting and using Class methods. This is the most straightforward approach. We can cast the value from one type to another using parentheses. Here’s an example of how to convert a double to a float using Casting:
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › Float-vs-Double-Whats-the-difference
Java double vs float: What's the difference?
If all of the values fall within the range of a float, it makes sense to use the smaller Java data type in this situation, otherwise the array elements needlessly consume memory. Data precision can be a problem with double and float types because binary numbers don’t always convert cleanly to decimals. For example, the following program prints out 11.3999 as the sum of 5.6 + 5.8:
🌐
Coderanch
coderanch.com › t › 374719 › java › converting-float-double
converting float to double (Java in General forum at Coderanch)
Here's some sample code: public static void testFloatToDouble() { Float f = new Float(18.4); Double d = new Double(f.floatValue()); System.out.println("Float: " + f); System.out.println("Float as double: " + f.doubleValue()); System.out.println("Float as Double: " + d); } And the results: Float: ...
Top answer
1 of 11
145

It's not that you're actually getting extra precision - it's that the float didn't accurately represent the number you were aiming for originally. The double is representing the original float accurately; toString is showing the "extra" data which was already present.

For example (and these numbers aren't right, I'm just making things up) suppose you had:

float f = 0.1F;
double d = f;

Then the value of f might be exactly 0.100000234523. d will have exactly the same value, but when you convert it to a string it will "trust" that it's accurate to a higher precision, so won't round off as early, and you'll see the "extra digits" which were already there, but hidden from you.

When you convert to a string and back, you're ending up with a double value which is closer to the string value than the original float was - but that's only good if you really believe that the string value is what you really wanted.

Are you sure that float/double are the appropriate types to use here instead of BigDecimal? If you're trying to use numbers which have precise decimal values (e.g. money), then BigDecimal is a more appropriate type IMO.

2 of 11
57

I find converting to the binary representation easier to grasp this problem.

float f = 0.27f;
double d2 = (double) f;
double d3 = 0.27d;

System.out.println(Integer.toBinaryString(Float.floatToRawIntBits(f)));
System.out.println(Long.toBinaryString(Double.doubleToRawLongBits(d2)));
System.out.println(Long.toBinaryString(Double.doubleToRawLongBits(d3)));

You can see the float is expanded to the double by adding 0s to the end, but that the double representation of 0.27 is 'more accurate', hence the problem.

   111110100010100011110101110001
11111111010001010001111010111000100000000000000000000000000000
11111111010001010001111010111000010100011110101110000101001000
🌐
Processing Forum
forum.processing.org › two › discussion › 2341 › double-to-float-conversion.html
Double to float conversion - Processing 2.x and 3.x Forum
I think that byte, short, and char work because there's an implicit cast to int when you pass them into the float() function. ... I believe that it is so too. B/c byte, short & double are completely neglected by Processing devs! I-) However, conversion function int() is much more flexible! Amongst the 8 primitive data-types, only double isn't accepted.
Find elsewhere
🌐
Scaler
scaler.com › home › topics › float vs double in java - difference you should know
Float Vs Double in Java - Difference You Should Know - Scaler Topics
March 27, 2024 - Both the float and double in Java represent or store real numbers in them, that is the numbers with fractions or decimal points. For example :1.23, 3.14, 1.1111. Both the float and double contains the approximate values as they are not precise.
🌐
GeeksforGeeks
geeksforgeeks.org › java › double-floatvalue-in-java-with-examples
Double floatValue() in Java with Examples - GeeksforGeeks
July 11, 2025 - Example 1: Java · // Java Program to Implement floatValue() Method // of Double Class // Class class GFG { // Main driver method public static void main(String[] args) { // Creating a Double object Double d = new Double(23); // Typecasting ...
🌐
LabEx
labex.io › tutorials › java-java-float-doublevalue-method-117648
Java Float to Double Conversion | Programming Tutorial | LabEx
java FloatDoubleValue · You will see the output on the terminal: Equivalent double value is 99.12000274658203 · In this lab, you learned how to use the doubleValue() method of the Float class to convert a Float object into its numerical double ...
🌐
Coderanch
coderanch.com › t › 411847 › java › convert-double-float
convert double to float ? (Beginning Java forum at Coderanch)
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor) Anto Telvin · Ranch Hand · Posts: 113 · posted 17 years ago · Number of slices to send: Optional 'thank-you' note: Send · thanks · Anto Telvin Mathew<br />Many of the life failures are people who did not realize how close they were to success when they give up. EDISON · reply reply · Bookmark Topic Watch Topic · New Topic · Boost this thread! Similar Threads · Explicit casting · converting float to double ·
🌐
Java67
java67.com › 2019 › 10 › deep-dive-into-float-and-double-datatypes-in-java.html
float and double data types in Java with Examples | Java67
If an expression involves both ... · double ten = 10.00; int nine = 9; // int result = ten*nine; // compile time error, need casting because result is double double result = ten * nine; //Ok 7) by default, any floating-point number (number with a decimal point )is double in Java. If you want to store a floating-point number as a float then use suffix for F or cast it into a float, as shown ...
🌐
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 ... directly to float. For example, if first 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 ...
🌐
Javatpoint
javatpoint.com › float-vs-double-java
Float Vs Double Java - Javatpoint
Float Vs Double Java with java tutorial, features, history, variables, object, programs, operators, oops concept, array, string, map, math, methods, examples etc.
🌐
Reddit
reddit.com › r/learnjava › [new cs student]trouble differentiating between floats and doubles--why is 23.5 considered a double?
r/learnjava on Reddit: [New CS Student]Trouble differentiating between floats and doubles--why is 23.5 considered a double?
July 7, 2021 -

From my textbook:

When you write a floating-point literal in your program code, Java assumes it to be of the double data type. A double value is not compatible with a float variable because a double can be much larger or smaller than the allowable range for a float. As a result, code such as the following will cause an error:

Example 1:

float number;
number = 23.5;       //Error!

You can force a double to be treated as a float, by suffixing it with the letter F or f. The preceding code can be rewritten in the following manner to prevent an error:

Example 2:

float number;
number = 23.5F;       //This will work.

===================================================

I can't figure out why example 1 produces an error. Why is 23.5 considered a double? I thought it was a float.

AFAIK, float numbers are precise up to 7 decimal digits of accuracy. 23.5 only has 1 decimal digit. What am I not understanding? I thought by typing 'float number;' you are declaring the number variable to be a float. Why would you need the extra step of adding an F?

Thanks

🌐
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 ... directly to float. For example, if first 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 ...
🌐
Oracle
docs.oracle.com › en › java › javase › 24 › docs › api › java.base › java › lang › Float.html
Float (Java SE 24 & JDK 24)
July 15, 2025 - In general, the two-step sequence ... directly to float. For example, if first 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 ...
🌐
Blogger
javarevisited.blogspot.com › 2016 › 05 › difference-between-float-and-double-in-java.html
Difference between float and double variable in Java? Example
By the way, the double type also ... numbers or real numbers are by default double in Java. If you want to store them into the float variable, you need to either cast them or use the prefix 'f' or 'F' as shown in our example....