Differentiate between the following: float and double
Advertisements
Question
Differentiate between the following:
float and double
Advertisements
Solution
|
float |
double |
|---|---|
|
1. The float data type is used to store single-precision floating-point numbers in Java. |
1. The double data type is used to store double-precision floating-point numbers in Java. |
|
2. The float data type occupies 4 bytes (32 bits) of memory. |
2. The double data type occupies 8 bytes (64 bits) of memory. |
|
3. The float data type provides approximately 6–7 decimal digits of precision. |
3. The double data type provides approximately 15–16 decimal digits of precision. |
|
4. The float data type is suitable when less precision is required. |
4. The double data type is suitable when greater precision is required. |
|
5. A floating-point literal must have the suffix f or F to be treated as a float. |
5. A floating-point literal is treated as a double by default in Java. |
|
6. Example: f |
6. Example: |
