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 ... 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 - Java™ Platform Standard Ed. 8 ... The Float class wraps a value of primitive type float in an object.
Discussions

floating point - What is float in Java? - Stack Overflow
I wrote this code: float b = 3.6; and I get this: Error:Unresolved compilation problem: Type mismatch: cannot convert from double to float Why? Whats the definition of float? More on stackoverflow.com
🌐 stackoverflow.com
When should I use double and when should I use float for Java?
On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge. If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options: Limiting your involvement with Reddit, or Temporarily refraining from using Reddit Cancelling your subscription of Reddit Premium as a way to voice your protest. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/learnprogramming
65
59
January 6, 2024
TIL a Python float is the same (precision) as a Java double
Just wait until you find out what an int is in python More on reddit.com
🌐 r/learnpython
85
108
May 1, 2025
memory - Why are floats still part of the Java language when doubles are mostly recommended instead? - Software Engineering Stack Exchange
In every place I've looked, it says that double is superior to float in almost every way. float has been made obsolete by double in Java, so why is it still used? I program a lot with Libgdx, and ... More on softwareengineering.stackexchange.com
🌐 softwareengineering.stackexchange.com
April 26, 2016
🌐
DataCamp
datacamp.com › doc › java › float
float Keyword in Java: Usage & Examples
Java keywordsIntroduction To JavaJava File HandlingJava Language BasicsJava ArraysJava Object-Oriented Programming ... The float keyword in Java is a primitive data type that represents a single-precision 32-bit IEEE 754 floating point.
🌐
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?
Both data types represent numbers with decimals, but a float is 32 bits in size while a double is 64 bits. A double is twice the size of a float — thus the term double. In Java, the Float and Double wrapper classes have two properties that ...
Find elsewhere
🌐
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 ...
🌐
iO Flood
ioflood.com › blog › java-float
Java Float Keyword Explained: Usage and Examples
February 26, 2024 - The ‘f’ after the value tells Java that the value is a float. Here’s a simple example of declaring and initializing a float variable in Java:
🌐
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 Java, a float is a primitive data type used to represent floating-point numbers. Floating-point numbers are numbers with a decimal point, such as 3.14, 2.718, or 0.0001.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.lang.float
Float Class (Java.Lang) | Microsoft Learn
The Float class wraps a value of primitive type float in an object. [Android.Runtime.Register("java/lang/Float", DoNotGenerateAcw=true)] public sealed class Float : Java.Lang.Number, IConvertible, IDisposable, Java.Interop.IJavaPeerable, ...
🌐
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 ...
🌐
Oracle
docs.oracle.com › en › java › javase › 18 › docs › api › java.base › java › lang › Float.html
Float (Java SE 18 & JDK 18)
August 18, 2022 - 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 the Float Object float output = b.floatValue(); // prfloating the output System.out.println("Float value of " + b + " is : " + output); } }
🌐
Reddit
reddit.com › r/learnpython › til a python float is the same (precision) as a java double
r/learnpython on Reddit: TIL a Python float is the same (precision) as a Java double
May 1, 2025 -

TL;DR in Java a "double" is a 64-bit float and a "float" is a 32-bit float; in Python a "float" is a 64-bit float (and thus equivalent to a Java double). There doesn't appear to be a natively implemented 32-bit float in Python (I know numpy/pandas has one, but I'm talking about straight vanilla Python with no imports).

In many programming languages, a double variable type is a higher precision float and unless there was a performance reason, you'd just use double (vs. a float). I'm almost certain early in my programming "career", I banged my head against the wall because of precision issues while using floats thus I avoided floats like the plague.

In other languages, you need to type a variable while declaring it.

Java: int age=30
Python: age=30

As Python doesn't have (or require?) typing a variable before declaring it, I never really thought about what the exact data type was when I divided stuff in Python, but on my current project, I've gotten in the habit of hinting at variable type for function/method arguments.

def do_something(age: int, name: str):

I could not find a double data type in Python and after a bunch of research it turns out that the float I've been avoiding using in Python is exactly a double in Java (in terms of precision) with just a different name.

Hopefully this info is helpful for others coming to Python with previous programming experience.

P.S. this is a whole other rabbit hole, but I'd be curious as to the original thought process behind Python not having both a 32-bit float (float) and 64-bit float (double). My gut tells me that Python was just designed to be "easier" to learn and thus they wanted to reduce the number of basic variable types.

🌐
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 - In this tutorial, we’ll discuss double and float and learn how to convert them into each other.
🌐
Baeldung
baeldung.com › home › java › java numbers › float vs. double in java
Float vs. Double in Java | Baeldung
January 4, 2025 - This article explores these differences in detail, aiming to guide developers in choosing the right type for tasks such as scientific computations, graphics processing, and financial analyses. Java provides two primitive data types for floating-point arithmetic: float and double.
🌐
Software Testing Help
softwaretestinghelp.com › home › java › java float tutorial with programming examples
Java Float Tutorial With Programming Examples
April 1, 2025 - Float is a single-precision value that has a width of 32 bits in storage. On some processors, this single precision is faster and takes less size when compared to the double-precision.
🌐
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 - The float keyword in Java is a primitive data type, and its size limit is 4 byte or 32 bits (1 byte = 8 bits) single-precision IEEE 754 (Standard for Floating-Point Arithmetic) floating-point number, that is it can allow up to 6 digits precision ...