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
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Float.html
Float (Java Platform SE 8 )
July 21, 2026 - Java™ Platform Standard Ed. 8 ... The Float class wraps a value of primitive type float in an object.
🌐
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.
🌐
Reddit
reddit.com › r/learnprogramming › when should i use double and when should i use float for java?
r/learnprogramming on Reddit: When should I use double and when should I use float for Java?
January 6, 2024 -

I am learning Java, and am confuse on when to choose double or float for my real numbers or int. It feels like, it doesn’t matter because from my limited experience (with Java) both of them deliver the same results, but I don’t want to go further down the learning curve with Java and have a bad habit of using either messing up my code, and not having a clue as to why. So, when should you use float and double?

float vs. double – What's the Key Difference?" Nov 2, 2024
r/learnprogramming
2y ago
Why is a double preferred over a float? Oct 24, 2011
r/java
15y ago
ELI5: difference between double and floating point data types May 17, 2014
r/explainlikeimfive
12y ago
what is the difference between double and float Dec 21, 2020
r/learnprogramming
5y ago
Java Double Precision Aug 24, 2020
r/java
6y ago
More results from reddit.com
🌐
DataCamp
datacamp.com › doc › java › float
float Keyword in Java: Usage & Examples
The float keyword in Java is a primitive data type that represents a single-precision 32-bit IEEE 754 floating point.
🌐
Baeldung
baeldung.com › home › java › java numbers › float vs. double in java
Float vs. Double in Java | Baeldung
January 4, 2025 - Java provides two primitive data types for floating-point arithmetic: float and double. Both adhere to the IEEE 754 standard, ensuring consistent behavior across platforms.
🌐
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 ...
Find elsewhere
🌐
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?
The key difference between a float and double in Java is that a double can represent much larger numbers than a float. Both data types represent numbers with decimals, but a float is 32 bits in size while a double is 64 bits.
Published: May 23, 2026
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › lang › Float.html
Float (Java SE 17 & JDK 17)
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.
🌐
Study.com
study.com › business courses › java programming tutorial & training
Java: Floating Point Numbers - Lesson | Study.com
October 3, 2018 - Floating point numbers are also called floating point literals in Java. For calculations using decimal values, Java supports two basic data types: float and double. Together, these support decimal or floating point numbers in the Java programming ...
🌐
Wikibooks
en.wikibooks.org › wiki › Java_Programming › Keywords › float
Java Programming/Keywords/float - Wikibooks, open books for an open world
The java.lang.Float class is the nominal wrapper class when you need to store a float value but an object reference is required.
🌐
Simplilearn
simplilearn.com › home › resources › software development › float vs double in java: key differences you should know
Float vs Double in Java: Key Differences You Should Know
November 17, 2025 - Explore the key differences between float and double in Java. Our comprehensive guide helps you choose the right type for your Java applications. Perfect for new coders!
🌐
ZetCode
zetcode.com › java › lang-float
Java Float Class - Complete Tutorial with Examples
The java.lang.Float class is a wrapper for the primitive float type, providing utility methods and constants for working with floating-point values.
🌐
Oracle
docs.oracle.com › en › java › javase › 22 › docs › api › java.base › java › lang › Float.html
Float (Java SE 22 & JDK 22)
July 16, 2024 - 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.
🌐
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.
🌐
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.Lang.IComparable
🌐
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 after the decimal.
🌐
Tutorialspoint
tutorialspoint.com › java › lang › java_lang_float.htm
Java - Float class with Examples
The Java Float class wraps a value of primitive type float in an object.
🌐
Medium
tarunjain07.medium.com › java-datatypes-notes-8e70959f4898
float datatypes in Java— [Notes]. **WIP | by Tarun Jain | Medium
September 5, 2022 - When expressing a float data type in Java, add the letter f to the end of the data type; otherwise, it will save as a double.
🌐
CodeGym
codegym.cc › java blog › java numbers › java float keyword
Java Float Keyword
June 30, 2022 - All real fractional numbers in Java are Double by default, and the syntax of the language also emphasizes this. If you really want to work with the float type, you need to specify it explicitly with an f terminating the number.