short Data Type in Java: Definition and Usage Explained
☰Fullscreen
Table of Content:
double Data Type
Double data type is also same as float data type which allows up-to 10 digits after decimal. The range for double datatype is from 1E–37 to 1E+37.
double Variable Declaration and Variable Initialization:
Variable Declaration : To declare a variable , you must specify the data type & give the variable a unique name.
double area ;
Variable Initialization : To initialize a variable you must assign it a valid value.
area = 334343.14 ;
float Variable Declaration and Variable Initialization in two steps:
double area; area = 334343.14;
Program
// A Java program to demonstrate double data type class CharDemo { public static void main(String args[]) { double area; area = 323323.14; System.out.println(area); } }
Output
323323.14 Press any key to continue . . .
double Variable Declaration and Variable Initialization in one line:
double area= 334343.14 ;
Program
// A Java program to demonstrate double data type class CharDemo { public static void main(String args[]) { double area = 323323.14; System.out.println(area); } }
Output
323323.14 Press any key to continue . . .
Difference between float and double
The size of float (single precision float data type) is 4 bytes. And the size of double (double precision float data type) is 8 bytes. Floating point variables has a precision of 6 digits whereas the precision of double is 14 digits.