Java's Primitive Data Types

boolean: 1-bit. May take on the values true and false only.

byte: 1 signed byte (two's complement). Covers values from -128 to 127.

short: 2 bytes, signed (two's complement), -32,768 to 32,767

int: 4 bytes, signed (two's complement). -2,147,483,648 to 2,147,483,647.

long: 8 bytes signed (two's complement). Ranges from -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807.

float: 4 bytes, IEEE 754. Covers a range from 1.40129846432481707e-45 to 3.40282346638528860e+38 (positive or negative).

double: 8 bytes IEEE 754. Covers a range from 4.94065645841246544e-324d to 1.79769313486231570e+308d (positive or negative).

char: 2 bytes, unsigned, Unicode, 0 to 65,535

🌐
DataCamp
datacamp.com › doc › java › double
double Keyword in Java: Usage & Examples
The range for double values is approximately from 4.9e-324 to 1.7e+308.
Discussions

Which is larger? Long vs Double
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. 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/javahelp
10
3
January 19, 2023
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
Java Double Precision
I found this useful the first time I encountered the strangeness of floating-point values: https://floating-point-gui.de/ Basically, it boils down to you can't represent an infinite continuum of real numbers using a finite number of bits. More on reddit.com
🌐 r/java
25
14
August 24, 2020
double keyword help
You would use double in the same way as you would use float. The type double is a 64-bit floating-point data type. It stores floating-point (decimal) numbers in the space of 64 bits (eight bytes). The type float is a 32-bit floating-point data type. It stores floating-point (decimal) numbers in the space of 32 bits (four bytes). The type double has double the bits available when compared to the float type, hence the name of the type. Using a double instead of a float will increase the exactness/precision of your calculations, because when you have more bits available for storage the number of decimals stored increases. More on reddit.com
🌐 r/javahelp
14
5
November 28, 2020
🌐
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?
From the output of the program above, we see the size difference between float and double Java types is: The upper range of a double in Java is 1.7976931348623157E308.
🌐
Oracle
docs.oracle.com › javadb › 10.10.1.2 › ref › rrefsqljdoubleprecision.html
DOUBLE PRECISION data type
These limits are the same as the java.lang.Double Java type limits. An exception is thrown when any double value is calculated or entered that is outside of these value ranges. Arithmetic operations do not round their resulting values to zero.
🌐
Baeldung
baeldung.com › home › java › java numbers › float vs. double in java
Float vs. Double in Java | Baeldung
January 4, 2025 - In contrast, a double extends this range significantly, from -1.7e-308 to +1.7e+308, making it the preferred choice for applications that demand greater numerical reach, such as scientific simulations or astronomical calculations.
Find elsewhere
🌐
Apache Commons
commons.apache.org › proper › commons-lang › apidocs › org › apache › commons › lang3 › DoubleRange.html
DoubleRange (Apache Commons Lang 3.20.0 API)
java.lang.Object · org.apache.commons.lang3.Range<Double> org.apache.commons.lang3.NumberRange<Double> org.apache.commons.lang3.DoubleRange · All Implemented Interfaces: Serializable · public final class DoubleRange extends NumberRange<Double> Specializes NumberRange for Doubles.
🌐
Quora
quora.com › What-is-the-range-of-the-double-data-type-in-Java
What is the range of the double data type in Java? - Quora
Answer (1 of 4): The range of double in Java is 1.7976931348623157 x 10^308 to 4.9406564584124654 x 10^-324. The java documentation mentions all such details of different data types and all the classes, interfaces and function that are shipped ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-data-types
Java Data Types - GeeksforGeeks
A 64-bit double-precision floating-point type and the default for decimal numbers. ... Size : 8 bytes (64 bits). It is recommended to go through rounding off errors in java.
Published   January 16, 2026
🌐
Apache Commons
commons.apache.org › proper › commons-lang › javadocs › api-2.4 › org › apache › commons › lang › math › DoubleRange.html
DoubleRange (Commons Lang 2.4 API)
Constructs a new DoubleRange with the specified minimum and maximum numbers (both inclusive). The arguments may be passed in the order (min,max) or (max,min). The getMinimum and getMaximum methods will return the correct values. ... Returns the minimum number in this range.
🌐
CodeGym
codegym.cc › java blog › java numbers › java double keyword
Java double keyword
February 19, 2025 - Float is 32 bits, of which 1 bit is signed bit, 8 bit for exponent and 23 bit for significand. It's range is ±3.40282347E + 38F i.e. 6-7 significant digits. The name double comes from double float.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Double.html
Double (Java Platform SE 8 )
October 20, 2025 - If the argument is 0xfff0000000000000L, the result is negative infinity. If the argument is any value in the range 0x7ff0000000000001L through 0x7fffffffffffffffL or in the range 0xfff0000000000001L through 0xffffffffffffffffL, the result is a NaN. No IEEE 754 floating-point operation provided ...
🌐
IBM
ibm.com › docs › en › i › 7.4.0
COBOL and Java Data Types
We cannot provide a description for this page right now
🌐
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 - We can use the double data type in Java when the memory is not a big concern, and if we want more accurate and precise results. If the value is not in the range offered by float, that is, if the digits after the decimal point of the value are more than the float precision, we must use double data type, in that case, to get the result more accurate.
🌐
Codefinity
codefinity.com › blog › Float-vs-Double
Float vs Double
The primary difference between float and double is the precision. Float is a single-precision float with about 7 decimal digits of precision and a range from approximately 1.4E-45 to 3.4E+38.
🌐
W3Schools
w3schools.com › java › java_data_types.asp
Java Data Types
Note: This rule makes Java safer, because the compiler will stop you if you try to mix up types by mistake. If you really need to change between types, you must use type casting or conversion methods (for example, turning an int into a double).
🌐
Coderanch
coderanch.com › t › 368695 › java › Range-Data-Type-double
Range of Data Type double (Java in General forum at Coderanch)
As per the Book, long Data Types Range is -9223372036854775808 to 9223372036854775807. I got an error message while compiling this above statement.The Error message is : "integer number too large: 922337203685477580".
🌐
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!
Top answer
1 of 3
38

Double is a wrapper class,

The Double class wraps a value of the primitive type double in an object. An object of type Double contains a single field whose type is double.

In addition, this class provides several methods for converting a double to a String and a String to a double, as well as other constants and methods useful when dealing with a double.

The double data type,

The double data type is a double-precision 64-bit IEEE 754 floating point. Its range of values is 4.94065645841246544e-324d to 1.79769313486231570e+308d (positive or negative). For decimal values, this data type is generally the default choice. As mentioned above, this data type should never be used for precise values, such as currency.

Check each datatype with their ranges : Java's Primitive Data Types.


Important Note : If you'r thinking to use double for precise values, you need to re-think before using it. Java Traps: double

2 of 3
29

In a comment on @paxdiablo's answer, you asked:

"So basically, is it better to use Double than Float?"

That is a complicated question. I will deal with it in two parts


Deciding between double versus float

On the one hand, a double occupies 8 bytes versus 4 bytes for a float. If you have many of them, this may be significant, though it may also have no impact. (Consider the case where the values are in fields or local variables on a 64bit machine, and the JVM aligns them on 64 bit boundaries.) Additionally, floating point arithmetic with double values is typically slower than with float values ... though once again this is hardware dependent.

On the other hand, a double can represent larger (and smaller) numbers than a float and can represent them with more than twice the precision. For the details, refer to Wikipedia.

The tricky question is knowing whether you actually need the extra range and precision of a double. In some cases it is obvious that you need it. In others it is not so obvious. For instance if you are doing calculations such as inverting a matrix or calculating a standard deviation, the extra precision may be critical. On the other hand, in some cases not even double is going to give you enough precision. (And beware of the trap of expecting float and double to give you an exact representation. They won't and they can't!)

There is a branch of mathematics called Numerical Analysis that deals with the effects of rounding error, etc in practical numerical calculations. It used to be a standard part of computer science courses ... back in the 1970's.


Deciding between Double versus Float

For the Double versus Float case, the issues of precision and range are the same as for double versus float, but the relative performance measures will be slightly different.

  • A Double (on a 32 bit machine) typically takes 16 bytes + 4 bytes for the reference, compared with 12 + 4 bytes for a Float. Compare this to 8 bytes versus 4 bytes for the double versus float case. So the ratio is 5 to 4 versus 2 to 1.

  • Arithmetic involving Double and Float typically involves dereferencing the pointer and creating a new object to hold the result (depending on the circumstances). These extra overheads also affect the ratios in favor of the Double case.


Correctness

Having said all that, the most important thing is correctness, and this typically means getting the most accurate answer. And even if accuracy is not critical, it is usually not wrong to be "too accurate". So, the simple "rule of thumb" is to use double in preference to float, UNLESS there is an overriding performance requirement, AND you have solid evidence that using float will make a difference with respect to that requirement.