Explain the Floating Point data tyре.
Advertisements
Question
Explain the Floating Point data tyре.
Explain
Advertisements
Solution
The Floating Point Data Type in Java is a primitive data type used to store numerical values containing decimal points. It is mainly used for calculations involving fractional numbers.
- float: It occupies 4 bytes (32 bits) of memory and stores decimal numbers with single precision (approximately 6–7 decimal digits).
- double: It occupies 8 bytes (64 bits) of memory and stores decimal numbers with double precision (approximately 15–16 decimal digits).
Example:
float price = 25.5f;
double salary = 45000.75;
Here, float and double are used to store decimal values with different levels of precision.
shaalaa.com
Is there an error in this question or solution?
