# The difference between float and double

Thank you.

We all know float and double as the primitive datatypes of any programming language. But plenty of us still get confused regarding the basic meaning of these datatypes.

In technical terms, float is known as the Single precision floating point datatype whereas double is considered to be double precision floating point datatype.

Now in simple terms, single precision floating point’s significand has a precision of about 24 bits which lasts up to 8 decimal digits and double precision floating point’s significand has a precision of 53 bits which lasts up to 16 decimal digits.

In summary, we can say that, float can allow maximum 8 decimal digits while double allows 16.

It is as simple as that.

Following  Java program will depict above scenario quite clearly.

 package samplejavaprograms;  public class DifferenceBetweenFloatAndDouble { public static void main(String[] args) { float f = 0.123456789f; double d = 0.1234567890d;               System.out.println(“Float : ” + f);               System.out.println(“Double : ” + d); } }

If you take a close look at the output, you will see that after the 7th digit of float, 8th digit is rounded off which clears the fact the float allows only 8 decimal digits and as far as double is concerned, it allows the same thing up to 16 decimal digits. Hope you had a great read. Suggestions and improvements are always welcome.