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 Compiler Java Exercises Java Quiz Java Code Challenges Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate ... The float keyword is a data type that can store fractional numbers from 3.4e−038 to 3.4e+038.
🌐
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.
🌐
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 › 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.
🌐
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.
🌐
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 ...
🌐
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 ...
Find elsewhere
🌐
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.
🌐
Tutorialspoint
tutorialspoint.com › home › java/lang › java float class
Java Float Class
September 1, 2008 - The Java Float class wraps a value of primitive type float in an object.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-program-to-illustrate-the-usage-of-floating
Java Program to Illustrate the Usage of Floating - GeeksforGeeks
September 7, 2021 - Float: It is a single-precision value that has 32 bits in storage. and this single precision is faster and does take less size compared to double precision. For java variables, we can use float while declaring or initializing for expected value ...
🌐
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 ...
🌐
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
🌐
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 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 ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › float-floatvalue-in-java-with-examples
Float floatValue() in Java with examples - GeeksforGeeks
July 11, 2025 - // Java code to demonstrate // Float floatValue() method class GFG { public static void main(String[] args) { // Float value Float a = 17.47f; // wrapping the Float value // in the wrapper class Float Float b = new Float(a); // floatValue of ...
🌐
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.
🌐
Javatpoint
javatpoint.com › float-keyword-in-java
Java float keyword - Javatpoint
DoubleBuffer limit() methods in Java with Examples · Java short Keyword · Java long Keyword · Java Versions History · Java String valueOf() Java Integer getInteger() Method · Package class · Java abstract Keyword · Java boolean Keyword · Java byte keyword · Java case keyword · Java char keyword · Java class keyword · Java double keyword · Java float keyword ·
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-lang-float-class-in-java
Java.Lang.Float class in Java - GeeksforGeeks
April 5, 2023 - Syntax : public static int compare(float x,float y) Parameters : x : float value y : another float value · Example: Java ·
🌐
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 ...