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
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.
🌐
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.
🌐
Tutorialspoint
tutorialspoint.com › java › lang › java_lang_float.htm
Java - Float class with Examples
static Class<Float> TYPE − This is the Class instance representing the primitive type float. This class inherits methods from the following classes − ... The following example shows the usage of Float class to get float from a string.
🌐
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.
🌐
iO Flood
ioflood.com › blog › java-float
Java Float Keyword Explained: Usage and Examples
February 26, 2024 - In this example, we declare a float variable named ‘num’ and initialize it with the value 1.11. The ‘f’ at the end of the number is necessary because Java interprets decimal numbers as double by default.
🌐
CodeGym
codegym.cc › java blog › java numbers › java float keyword
Java Float Keyword
June 30, 2022 - float myFloat2 = 2E22f; double myDouble2 = 3e10; If you use large enough numbers in their "normal" representation, Java will display them immediately in exponential form. Let’s have an example:
Find elsewhere
🌐
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 ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-program-to-illustrate-the-usage-of-floating
Java Program to Illustrate the Usage of Floating - GeeksforGeeks
September 7, 2021 - The default value in java is 0.0f and its size is 4 bytes. Float in java can have negative values.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-lang-float-class-in-java
Java.Lang.Float class in Java - GeeksforGeeks
April 5, 2023 - Examples · Quizzes · Projects · Cheatsheet · DSA in Java · Java Collection · Last Updated : 5 Apr, 2023 · Float class is a wrapper class for the primitive type float which contains several methods to effectively deal with a float value like converting it to a string representation, and vice-versa.
🌐
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 ...
🌐
Dot Net Perls
dotnetperls.com › float-java
Java - float Number - Dot Net Perls
Here are two syntax forms for creating a float value. We can use (float) to specify the type. And the lowercase "f" specifies a float literal. Tip In Java we find the handy "BYTES" constants.
🌐
Tutorialspoint
tutorialspoint.com › java › lang › number_floatvalue.htm
Java - Number floatValue() Method
package com.tutorialspoint; public class NumberFloatVal { public static void main(String[] args) { // get a number as byte Byte x = -120; // print their value as float System.out.println("x as byte: " + x + ", x as float: " + x.floatValue()); } }
🌐
LabEx
labex.io › tutorials › java-how-to-create-a-float-object-in-java-413978
How to create a Float object in Java | LabEx
The Float class in Java has a wide ... // Example: Calculating the area of a circle float radius = 5.0f; float area = (float) Math.PI * radius * radius; System.out.println("The area of the circle is: " + area);...
🌐
Home and Learn
homeandlearn.co.uk › java › short_float_variables.html
java for complete beginners - short and float variables
However, change the double to float. Then add the letter "f" to the end of the numbers. So your code should look like this: When you run the above code, the answer is now 0.5048077. Java has taken the first 6 numbers after the point and then rounded up the rest.
🌐
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 ...
🌐
ZetCode
zetcode.com › java › float-types
Java Floating-Point Numbers - Complete Guide
This section explores Java's two floating-point types: float and double. Both adhere to IEEE 754, differing in size and precision for varied use cases. Grasping their ranges and limits is key to choosing wisely. The example below highlights their properties with sample values.
🌐
Scaler
scaler.com › home › topics › java float
Java Float - Scaler Topics
May 4, 2023 - In this example, we are going to see a java program that creates a float variable and a string variable and then uses the valueOf() method of the java Float class to convert them into a Float value and then prints the results.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Float.html
Float (Java Platform SE 8 )
July 21, 2026 - Returns the smaller of two float values as if by calling Math.min. ... Java™ Platform Standard Ed. 8 ... Submit a bug or feature For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples...