🌐
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. Note that you should end the value with a "d": Read more about data types in our Java Data Types Tutorial.
🌐
Home and Learn
homeandlearn.co.uk › java › double_variables.html
java for complete beginners - double variables
Change the int from your previous code to double. So change this: ... Leave the rest of the programme as it is. Your coding window should look like this: Run your programme again. The output window should look like this: Try changing the values stored in first_number and second_number. Use any values you like. Run your programme and see what happens. In the next part, you'll learn about two more Java variable types: short and float.
🌐
Software Testing Help
softwaretestinghelp.com › home › java › java double – tutorial with programming examples
Java Double - Tutorial With Programming Examples
April 1, 2025 - We have initialized two double variables and calculated the difference between their values. Again we have initialized two variables using Big-Decimal class with the same value and calculated their difference. Finally, we printed both the values and you can see the difference between them. The calculated value of Big Decimal was automatically rounded-off. import java.math.BigDecimal; public class example { public static void main(String[] args) { // Initialized two double numbers double length1 = 1.06; double breadth1 = 1.07; // Subtracting length and breadth double sub = breadth1-length1; Sys
🌐
W3Schools
w3schools.com › java › ref_scanner_nextdouble.asp
Java Scanner nextDouble() Method
// Create a scanner object Scanner ...Obj.nextDouble()); } else { myObj.next(); } } The nextDouble() method returns a double value containing the number represented by the next token....
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › lang › Double.html
Double (Java Platform SE 7 )
P where Sign, FloatingPointLiteral, HexNumeral, HexDigits, SignedInteger and FloatTypeSuffix are as defined in the lexical structure sections of The Java™ Language Specification, except that underscores are not accepted between digits. If s does not have the form of a FloatValue, then a NumberFormatException is thrown. Otherwise, s is regarded as representing an exact decimal value in the usual "computerized scientific notation" or as an exact hexadecimal value; this exact numerical value is then conceptually converted to an "infinitely precise" binary value that is then rounded to type double by the usual round-to-nearest rule of IEEE 754 floating-point arithmetic, which includes preserving the sign of a zero value.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Double.html
Double (Java Platform SE 8 )
October 20, 2025 - P where Sign, FloatingPointLiteral, HexNumeral, HexDigits, SignedInteger and FloatTypeSuffix are as defined in the lexical structure sections of The Java™ Language Specification, except that underscores are not accepted between digits. If s does not have the form of a FloatValue, then a NumberFormatException is thrown. Otherwise, s is regarded as representing an exact decimal value in the usual "computerized scientific notation" or as an exact hexadecimal value; this exact numerical value is then conceptually converted to an "infinitely precise" binary value that is then rounded to type double by the usual round-to-nearest rule of IEEE 754 floating-point arithmetic, which includes preserving the sign of a zero value.
🌐
iO Flood
ioflood.com › blog › java-double
Java Double Keyword: Your Guide to Decimal Precision
February 26, 2024 - The double keyword is used to identify a data type in Java that is used to store decimal numbers, instantiated with the syntax double var = 3.14;. It provides a way to work with numbers that have a decimal point and need a high degree of precision.
🌐
W3Schools
w3schools.com › java › java_data_types_numbers.asp
Java Numbers
Even though there are many numeric types in Java, the most used for numbers are int (for whole numbers) and double (for floating point numbers). However, we will describe them all as you continue to read. The byte data type can store whole numbers from -128 to 127. This can be used instead of int or other integer types to save memory when you are certain that the value will be within -128 and 127:
🌐
Tutorialspoint
tutorialspoint.com › home › java/lang › java double value method
Java Double Value Method
September 1, 2008 - This method returns the double value after conversion. The following example shows the usage of Java Number doubleValue() method. Here, we are instantiating an Integer object and initializing it. The method is then invoked on this object.
Find elsewhere
🌐
Javatpoint
javatpoint.com › double-keyword-in-java
Java double keyword - Javatpoint
Java double keyword - The Java double keyword is a primitive data type. It is a double-precision 64-bit IEEE 754 floating point. It is used to declare the variables and methods. It generally represents the decimal numbers.
🌐
Tutorialspoint
tutorialspoint.com › java › lang › double_doublevalue.htm
Java - Double doubleValue() method
The following example shows the usage of Double doubleValue() method to get a double primitive value of given negative Double object of zero value. We've initialized a Double object with a given negative zero value.
🌐
DataCamp
datacamp.com › doc › java › double
double Keyword in Java: Usage & Examples
Precision: Use double when you need more precision than float can provide. The double data type is more precise but also consumes more memory (64 bits). Avoid Using for Exact Values: Avoid using double for exact values like currency.
🌐
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). ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-number-doublevalue-method
Java Number.doubleValue() Method - GeeksforGeeks
May 15, 2025 - Example 2: In this example, we are going to use doubleValue() with smaller values. ... // Java program to demonstrate the // use of doubleValue() method import java.lang.Number; public class Geeks { public static void main(String[] args) { // Create an Integer object with a small value Integer i = Integer.valueOf(123); // Convert Integer to double double doubleFromInt = i.doubleValue(); System.out.println("Integer as double: " + doubleFromInt); // Create a Float object with a small value Float f = Float.valueOf(9876f); // Convert Float to double double doubleFromFloat = f.doubleValue(); System.out.println("Float as double: " + doubleFromFloat); } }
🌐
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 lower range of a float in Java is 1.4E-45. ... Specify the type as double. Provide a variable name. Assign a value within the range of a double.
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.

🌐
Netlify
w3schools.netlify.app › learnjava › ref_keyword_double
Java double keyword
The double keyword is a data type that can store fractional numbers from 1.7e−308 to 1.7e+308. ... Read more about data types in our Java Data Types Tutorial. ... W3School is optimized for learning, testing, and training. Examples might be simplified to improve reading and basic understanding.
🌐
Java
download.java.net › java › early_access › valhalla › docs › api › java.base › java › lang › Double.html
Double (Java SE 23 & JDK 23 [build 1])
These are the closest float and double values, respectively, to the numerical value of 0.1. These results are consistent with a float value having the equivalent of 6 to 9 digits of decimal precision and a double value having the equivalent of 15 to 17 digits of decimal precision.
🌐
GeeksforGeeks
geeksforgeeks.org › number-doublevalue-method-in-java-with-examples
Number.doubleValue() method in java with examples | GeeksforGeeks
June 20, 2018 - The java.lang.Short.doubleValue() method of Short class is a built in method in Java which is used to return the value of the Short object as a double. Syntax: public double doubleValue() Return type: It return the value of ShortObject as double.