Float and double, both are used to represent floating point numbers in programming languages. The main difference between them is their range and the number of bits/bytes they use.
In Java, float uses 4 bytes and has comparatively less range than double which uses 8 bytes. Float gives you presion up to 6 decimal places while double gives you precison up to 16 decimal places.
Let's take an example, suppose you made a program in which a variable is used to represent distance. Now if we want presion up to few decimal places like 1.23, 5.3821, etc we can use float. But for precision up to more decimal places like 1.23728164829 we will use double.
Happy Coding :)
Top comments (0)