๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ ref_keyword_double.asp
Java double Keyword
The double keyword is a data type that can store fractional numbers from 1.7eรขห†โ€™308 to 1.7e+308.
๐ŸŒ
DataCamp
datacamp.com โ€บ doc โ€บ java โ€บ double
double Keyword in Java: Usage & Examples
double negativeInfinity = Double.NEGATIVE_INFINITY;Powered by ... These constants can be used to handle special cases in floating-point arithmetic, such as results of undefined operations. Build your Java skills from the ground up and master programming concepts.
๐ŸŒ
Home and Learn
homeandlearn.co.uk โ€บ java โ€บ double_variables.html
java for complete beginners - double variables
The double variable is also used to hold floating point values. A floating point value is one like 8.7, 12.5, 10.1. In other words, it has a "point something" at the end. If you try to store a floating point value in an int variable, NetBeans will underline the faulty code.
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ java โ€บ double_keyword_in_java.htm
Java - double Keyword (double Data Type)
Following example shows the usage of double primitive data type in an expression. We've created two double variables and assigned them double values. Then we're creating a new double variable doubleResult to assign it the sum of double variables.
๐ŸŒ
CodeGym
codegym.cc โ€บ java blog โ€บ java numbers โ€บ java double keyword
Java double keyword
February 19, 2025 - 3.0 This is because the Java machine first divides two integers (and gets 3), and then stores this value in a variable of type double, and gets 3.0 as a result. To get not integer, but usual division, you need to cheat. For example, write one of the numbers as a real number (then the whole expression is automatically converted to real).
๐ŸŒ
Software Testing Help
softwaretestinghelp.com โ€บ home โ€บ java โ€บ java double โ€“ tutorial with programming examples
Java Double - Tutorial With Programming Examples
April 1, 2025 - Java double is used to represent floating-point numbers. It uses 64 bits to store a variable value and has a range greater than float type. ... In this example, we are calculating the square root of the area of a rectangle.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-lang-double-class-java
Java.Lang.Double Class in Java - GeeksforGeeks
July 23, 2025 - B. Double(String s): Creates a Double-object initialized with the parsed double value provided by string representation where it takes a string representation of the byte value as a parameter.
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ java โ€บ lang โ€บ number_doublevalue.htm
Java - Number doubleValue() Method
public class NumberDoubleVal { public static void main(String[] args) { // get a number as integer Integer x = new Integer(123456); // print their value as double System.out.println("x as integer :" + x + ", x as double:" + x.doubleValue()); ...
๐ŸŒ
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?
When Java encounters a decimal in a program, or a calculation generates a floating point number, Java treats the number as a double. For example, both of the following lines of code fail to compile because Java assumes that any decimal is a double.
Published: May 23, 2026
Find elsewhere
๐ŸŒ
BeginnersBook
beginnersbook.com โ€บ 2013 โ€บ 12 โ€บ how-to-convert-string-to-double-in-java
Java Convert String to Double examples
September 11, 2022 - Lets see the complete example of conversion using Double.valueOf(String) method. public class JavaExample{ public static void main(String args[]){ String str = "122.111"; /* Convert String to double using * valueOf(String) method of Double * wrapper class */ double dnum = Double.valueOf(str); ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-number-doublevalue-method
Java Number.doubleValue() Method - GeeksforGeeks
May 15, 2025 - The doubleValue() method is helpful when we want to convert different number types like Integer, Float, or Long, into a double.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ double-doublevalue-method-in-java-with-examples
Double doubleValue() method in Java with examples - GeeksforGeeks
July 11, 2025 - // Java code to demonstrate // Double doubleValue() method class GFG { public static void main(String[] args) { // Double value Double a = 17.47; // wrapping the Double value // in the wrapper class Double Double b = new Double(a); // doubleValue ...
๐ŸŒ
Programiz PRO
programiz.pro โ€บ discuss โ€บ java โ€บ how-to-print-double-values-in-java
How to print double values in Java?
Good question! To print double values in Java, you can use the same `System.out.println()` method that you've already seen. Just like with integers, you can write a double value directly without using quotation marks, but you should remember to include a decimal point. Hereโ€™s an example:
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.

๐ŸŒ
YouTube
youtube.com โ€บ watch
Java Double Tutorial: What is a Double in Java? Doubles Explained for Beginners & Experienced - YouTube
Java Double Tutorial: What is a Double in Java? Doubles Explained for Beginners & ExperiencedJava Double Tutorial: Master Decimal NumbersUnderstanding the Ja...
Published: July 11, 2025
๐ŸŒ
Mkyong
mkyong.com โ€บ home โ€บ java โ€บ how to format a double in java
How to format a double in Java | mkyong.com
July 23, 2020 - package com.mkyong.io.utils; import java.util.Locale; public class FormatDouble1 { public static void main(String[] args) { String input = "1234567890.123456"; double d = Double.parseDouble(input); // 2 decimal points System.out.println(Str...
๐ŸŒ
Dot Net Perls
dotnetperls.com โ€บ double-java
Java - double Number - Dot Net Perls
In Java a double is twice the size of a floatโ€”it is 8 bytes (which is equal to 64 bits).
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ java โ€บ lang โ€บ java_lang_double.htm
Java - Double class
static Class<Double> TYPE โˆ’ This is the class instance representing the primitive type double ยท This class inherits methods from the following classes โˆ’ ... The following example shows the usage of Double class to get double from a string.