Java

What Is Double Keyword In Java

The decimal point values stored by the double keyword’s data type range from 1.7e-308 to 1.7e+308. Since this range is shown in “scientific notation,” you may think of 1.7e+308 as being identical to 17 followed by 307 zeroes in conventional form.

public class JavaExample {
  public static void main(String[] args) {
    double num = 2005.455d; //a double variable
    System.out.println(num); //prints the value of num
  }
}

Output:

2005.455

If a float data type can store floating point numbers and serves the same function, why do we need a double data type? A double data type may be used for both extremely big and extremely small values since it has a wider range than a float data type.

Example of double keyword with scientific notation

The range of the double data type was initially represented using scientific notation. To further grasp this notation, let’s use an example.

public class JavaExample {
  public static void main(String[] args) {
    double num = 101e+4; //equal to 101*10^4
    double num2 = 50e-4; //equal to 50*10^-4
    System.out.println(num);
    System.out.println(num2);
  }
}

Output:

1010000.0
0.005

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button