English

Differentiate between the following: float and double

Advertisements

Question

Differentiate between the following:

float and double

Distinguish Between
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: float a = 12.5f;

6. Example: double a = 12.5;

shaalaa.com
  Is there an error in this question or solution?
Chapter 6: Variables and Expressions - EXERCISE [Page 132]

APPEARS IN

Dheeraj Mehrotra Computer Science [English] Class 12
Chapter 6 Variables and Expressions
EXERCISE | Q 30. (b) | Page 132
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×