Javatpoint Logo
Javatpoint Logo

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.

Points to remember

  • The double covers a range from 4.94065645841246544e-324d to 1.79769313486231570e+308d (positive or negative).
  • Its default value is 0.0d.
  • Its default size is 8 byte.
  • It is the default type for decimal numbers.
  • It is not a good approach to use double for precise values, such as currency.

Examples of Java double keyword

Example 1

Let's see a simple example to display double type variable.

Output:

num: 5.5

Example 2

In this example, we provide integer value to double variable. Here, compiler implicitly typecast integer to double and display the corresponding value in decimal form.

Output:

num1: 5.0
num2: 10.0

Example 3

Let's see an example to test the bigger decimal value.

Output:

num1: 5.81216732323433E8
num2: 7.83684987683688

Example 4

In this example, we provide float value to decimal variable.

Output:

num1: 56.34000015258789
num2: 34.0

Example 5

In this example, we provide the maximum range of decimal value.

Output:

num1: 4.9E-324
num2: 1.7976931348623157E308

Example 6

In this example, we provide the value in scientific notation

Output:

num1: 1873.2
num2: 1873.2

Example 7

Let's see an example to create a method of the double return type.

Output:

62.5
Next TopicJava Keywords




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA