Explore Courses Blog Tutorials Interview Questions
0 votes
in Java by (6.5k points)
If they're both used for storing fractional/decimal values, why do two such datatypes exist?

1 Answer

0 votes
by (11.3k points)

Yes, they both are used to store decimal point values.

But the difference comes when the sizes of both the datatypes are concerned. In Java, the Float datatype is of 4 bytes (32bit) and the Double datatype is of 8 bytes (64 bit). This means that when compared to Float, Double can store twice the size of data. Float has the capacity for Single Precision while Double has the capacity for Double Precision. This means that you can specify larger values and define a decimal point to an even higher precision level (double the first) in Double. 

In your hands-on projects to learn java, it is important to reduce the memory overhead of the program i.e. refrain from using large datatypes when you can avoid it.  

Related questions

Browse Categories