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 ... Q&A ... 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 )
April 21, 2026 - 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.
🌐
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 ...
🌐
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:
Find elsewhere
🌐
Study.com
study.com › business courses › java programming tutorial & training
Java: Floating Point Numbers - Lesson | Study.com
October 3, 2018 - A float data type in Java stores a decimal value with 6-7 total digits of precision. So, for example, 12.12345 can be saved as a float, but 12.123456789 can't be saved as a float.
🌐
Quora
quora.com › Why-if-we-declare-a-float-variable-in-Java-we-write-f-3-14f
Why if we declare a float variable in Java we write f (3.14f)? - Quora
Answer (1 of 3): Because without the “f” the number would be implicitly created as double. There are things called literals [1] which are helpful to specify the exact data type for a hardcoded number. Some examples in Java (you can find them all in the footnote): * 123456L or 123456l => long ...
🌐
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
🌐
Sololearn
sololearn.com › en › Discuss › 2910779 › can-java-functions-accept-variables-that-are-floats
Can Java functions accept variables that are floats?
Sololearn is the world's largest community of people learning to code. With over 25 programming courses, choose from thousands of topics to learn how to code, brush up your programming knowledge, upskill your technical ability, or stay informed about the latest trends.
🌐
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
Answer (1 of 6): A float data type in Java stores a decimal value with 6-7 total digits of precision. 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...
🌐
Coderanch
coderanch.com › t › 565092 › java › Java-floats
Java floats (Beginning Java forum at Coderanch)
January 20, 2012 - I have written a program to demonstrate that, if you try hard enough, you can find places where a float is not precise to 1 significant figureIf you add a 3 at the end of that number, making 0.0000000000000000000000000000000000000000000023, you get a slightly different output! ... Thanks for all the replies. So just to make sure I'm understanding this correctly ... in my example, the 2nd number (coming down from 1/15000000) will be more accurate since it has more significant digits due to the way that floats truncate?
🌐
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 ...
🌐
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 ...
🌐
W3Schools
w3schools.com › java › java_data_types.asp
Java Data Types
Java Examples Java Videos Java ... in Java must be a specified data type: int myNum = 5; // Integer (whole number) float myFloatNum = 5.99f; // Floating point number char myLetter = 'D'; // Character boolean myBool = true; ...
🌐
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.
🌐
Codefinity
codefinity.com › blog › Float-vs-Double
Float vs Double
float myFloat = 3.14f; // Notice the 'f' suffix, specifying a float literal · A double in C and C++ offers more precision, typically up to 15 decimal digits. It is declared with the keyword double.
🌐
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: