double data type in Java
The double data type is also a floating point number. It is called double because it has a double-precision decimal number.
nanadwumor
- The double data type is a floating point number.
- It is double precision data type
- The range is 4.9406564584124654 x 10-324 to 1.7976931348623157 x 10308. The number can be positive or negative.
RECOMMENDED ARTICLES
Variables and Literals in Java
Variables are used in many situations. For Instance, game applications use variables to collect your name when you sign in; to store and keep track of your number of trials, successes and failures. In Java, a variable is a container used to store...
The print and println methods in Java
The print() and println() methods are Java's predefined methods used to display text output on the console. These methods are part of the Java API. The print and println methods are used to print string of characters onto the console The print...
float data type in Java
It is a floating point number. It has single precision data type. It stores a floating point number of 7 digits of accuracy. The float data type is a floating point number. It has single precision data type The float type is stored in 32 bits of...
The double data type is also a floating point number. It is called double because it has a double-precision decimal number. The double data type has 15 digits of accuracy.
The double data type is stored in 64 bits of memory. 8 bits gives a byte so double has 8 bytes of memory.
Join Other Subscribers on Our YouTube Channel and Don’t Miss a thing!
double has twice as much memory as the float data type.
double has a much larger range of possible values than the float type.
The range is 4.9406564584124654 x 10-324 to 1.7976931348623157 x 10308. The number can be positive or negative.
Declaring an double variable
We declare double the same as any other type :
double weight;
double height;
Alternatively, you can also declare all double variables in a row. That’s,
double height, weight;
Program demonstrates double data type
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
//Program demonstrates the double data type public class DoubleVariable { public static void main(String[] args) { double amount, discount; //'amount' and 'discount' are both declared as double amount=50.5; //amount is assigned the double value, 50.5 discount=1.5; //discount is assigned the double value, 1.5 System.out.println("The amount is $" + amount + " and the discount is " + discount + "%"); } } |
Output
Writing floating point numbers in Scientific notation
A number in Scientific notation is in the form a×10^n where a>=1 and n is an integer.
We can write floating point numbers in scientific notation. Example: 2751632 can be written as 2.751632 × 10^6. You can also write 0.00001532 as 1532×10^-5.
In Java, the letter E or e is used to represent the figures in the scientific notation. That’s,
2.751632 × 10^6 is typed as 2.751632E6 in Java.
1532×10^-5 is typed as 1532e-5.
Program demonstrates floating point numbers in scientific notation
1 2 3 4 5 6 7 8 9 10 11 |
//Program demonstrates floating point numbers in scientific notation public class ScientificFloat { public static void main(String[] args) { double distance=1.265432e12; System.out.print("The galaxies are " + distance + " meters apart"); } } |
Output
You May Also Like…
Variables and Literals in Java
Variables are used in many situations. For Instance, game applications use variables to collect...
The print and println methods in Java
The print() and println() methods are Java's predefined methods used to display text output on the...
float data type in Java
It is a floating point number. It has single precision data type. It stores a floating point...
0 Comments