Java - Data Types double type

Introduction

Java double data type uses 64 bits to store a floating-point number in the IEEE 754 standard format.

A floating-point number represented in 64 bits according to IEEE 754 standard is known as a double-precision floating-point number.

Java double type can represent a number from 4.9 x 10^-324 to 1.7 x 10^308 (approx.).

All real numbers are called double literals. A double literal may optionally end with d or D, for example, 12.34d.

Both 12.34 and 12.34d represent the same double literal.

double type literal

A double literal can be expressed in the following two formats:

  • Decimal number format
  • Scientific notation

Examples of double literals in decimal number format are as follows.

8 is an int literal whereas 8D, 8., and 8.0 are double literals.

  
d1 = 8D 
d2 = 8.; 
d3 = 8.0; 
d4 = 8.D; 
d5 = 8.1234; 
d6 = 85.0;  

Demo

public class Main {
  public static void main(String[] args) {
    double d1 = 8D;
    double d2 = 8.;
    double d3 = 8.0;
    double d4 = 8.D;
    double d5 = 8.1234;
    double d6 = 85.0;
    System.out.println(d1);/*from w w w. ja va2 s.  com*/
    System.out.println(d2);
    System.out.println(d3);
    System.out.println(d4);
    System.out.println(d5);
    System.out.println(d6);

  }
}

Result

Use scientific notation to express double literals.

  
d1 = 32.5E-1; 
d2 = 0.325E+1; 
d3 = 0.325E1; 
d4 = 0.0325E2; 
d5 = 0.0325e2; 
d6 = 32.5E-1D; 
d7 = 0.325E+1d; 
d8 = 0.325E1d; 
d9 = 0.0325E2d; 

Demo

public class Main {
  public static void main(String[] args) {
    double d1 = 32.5E-1; 
    double d2 = 0.325E+1; 
    double d3 = 0.325E1; 
    double d4 = 0.0325E2; 
    double d5 = 0.0325e2; 
    double d6 = 32.5E-1D; 
    double d7 = 0.325E+1d; 
    double d8 = 0.325E1d; 
    double d9 = 0.0325E2d; 

    System.out.println(d1);/*from  w  w w . ja  va 2 s .co m*/
    System.out.println(d2);
    System.out.println(d3);
    System.out.println(d4);
    System.out.println(d5);
    System.out.println(d6);
    System.out.println(d7);
    System.out.println(d8);
    System.out.println(d9);
    
  }
}

Result

Exercise