In Java, when you type a decimal number as 3.6, its interpreted as a double. double is a 64-bit precision IEEE 754 floating point, while floatis a 32-bit precision IEEE 754 floating point. As a float is less precise than a double, the conversion cannot be performed implicitly.

If you want to create a float, you should end your number with f (i.e.: 3.6f).

For more explanation, see the primitive data types definition of the Java tutorial.

Answer from Nicolas on Stack Overflow
🌐
W3Schools
w3schools.com › java › ref_keyword_float.asp
Java float Keyword
Java Examples Java Videos Java ... ... The float keyword is a data type that can store fractional numbers from 3.4e−038 to 3.4e+038....
🌐
DataCamp
datacamp.com › doc › java › float
float Keyword in Java: Usage & Examples
Here, we declare two float variables pi and gravity with values 3.14 and 9.8 respectively. The f or F suffix is required to indicate that these literals are of type float.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Float.html
Float (Java Platform SE 8 )
October 20, 2025 - If the argument is any value in the range 0x7f800001 through 0x7fffffff or in the range 0xff800001 through 0xffffffff, the result is a NaN. No IEEE 754 floating-point operation provided by Java can distinguish between two NaN values of the same type with different bit patterns.
🌐
Software Testing Help
softwaretestinghelp.com › home › java › java float tutorial with programming examples
Java Float Tutorial With Programming Examples
April 1, 2025 - As far as Java variables are concerned, we can use float while initializing or declaring any variable that may expect the output to be fractional. ... In this example, we have initialized two float variables n1 and n2 with some value.
🌐
LabEx
labex.io › tutorials › java-how-to-print-a-java-float-and-its-string-representation-414109
How to print a Java float and its String representation | LabEx
In the above example, we declare a float variable myFloat and assign it the value 3.14159. When we print the value, we can see that it is displayed with a limited precision. Understanding the behavior of floats is crucial when working with decimal ...
🌐
Tutorialspoint
tutorialspoint.com › home › java/lang › java float class
Java Float Class
September 1, 2008 - Explore the Java Float class, its methods, and how to use it effectively in your Java applications. Learn about float data type, precision, and conversion.
🌐
iO Flood
ioflood.com › blog › java-float
Java Float Keyword Explained: Usage and Examples
February 26, 2024 - In Java, the float keyword identifies a data type that can hold decimal numbers, created with the float keyword before the variable name, and must have an ‘f’ after the value, such as float num = 1.11f.
Find elsewhere
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › lang › Float.html
Float (Java Platform SE 7 )
If the argument is any value in the range 0x7f800001 through 0x7fffffff or in the range 0xff800001 through 0xffffffff, the result is a NaN. No IEEE 754 floating-point operation provided by Java can distinguish between two NaN values of the same type with different bit patterns.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.lang.float
Float Class (Java.Lang) | Microsoft Learn
[<Android.Runtime.Register("java/lang/Float", DoNotGenerateAcw=true)>] type Float = class inherit Number interface IConvertible interface IComparable interface IJavaObject interface IDisposable interface IJavaPeerable
🌐
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:
🌐
LabEx
labex.io › tutorials › java-how-to-declare-a-float-variable-in-java-415688
How to declare a float variable in Java | LabEx
It's also possible to perform arithmetic operations with float variables, just like with other numeric data types: float a = 2.5f; float b = 3.7f; float c = a + b; // c will be 6.2f · Overall, the float data type is a useful tool for working ...
🌐
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 addition, this class provides ... with a float. This is a value-based class; programmers should treat instances that are equal as interchangeable and should not use instances for synchronization, or unpredictable behavior may occur. For example, in a future release, synchronization may fail. The class java.lang.Double ...
🌐
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.
🌐
Tutorialspoint
tutorialspoint.com › home › java/lang › java float value method
Java Float Value Method
September 1, 2008 - Following is the syntax for Java Number floatValue() method ... This method does not accept any parameters. This method returns the float value after converting the given numeric value. The following example shows the usage of Java Number floatValue() method.
🌐
LabEx
labex.io › tutorials › java-how-to-get-user-input-for-a-java-float-414040
How to get user input for a Java float | LabEx
In the example above, we declare a float variable myFloat and assign it the value 3.14. The f suffix is used to indicate that the value is a float literal, as opposed to a double literal, which would be represented without the suffix (e.g., 3.14).
🌐
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 - For example, 123 × 10-21 is formatted as 1.23E-19. To create localized string representations of a floating-point value, use subclasses of NumberFormat. ... This method corresponds to the general functionality of the convertToDecimalCharacter operation defined in IEEE 754; however, that operation ...
🌐
Quora
quora.com › How-can-we-use-float-values-in-Java-as-they-give-errors-at-the-time-of-execution
How can we use float values in Java, as they give errors at the time of execution? - Quora
So for example 12.12345 can be saved as a float, but 12.123456789 cannot be saved as a float. When representing a float data type in Java, we should append the letter f to the end of the data typ...
🌐
Javatpoint
javatpoint.com › java-float
Java Float - Javatpoint
Java Float class methods with Examples on byteValue(), compare(), compareTo(), doubleValue(), equals(), floatToIntBits(), floatToRawIntBits(), floatValue(), hashCode(), intBitsToFloat(), intValue(), longValue(), parseFloat(), valueOf(), shortValue() etc.