Comparison of double and float primitive types in Java Last Updated : 06 Mar, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report Consider the following two codes in Java: Java // This program prints true class Geeksforgeeks { public static void main(String args[]) { float f = 5.25f; double d = 5.25 System.out.println(f == d); } } Output true Java // But this program prints false. class Geeksforgeeks { public static void main(String args[]) { float f = 5.1f; double d = 5.1; System.out.println(f == d); } } Output false Explanation: The output is true in the first example and false in second. We know that precisions of float and double are different. Size of mantissa for float is 24 and 53 for double. Let us consider the first example of 5.25. Binary representation of integral part is 101 and binary representation of part of the dot is 0.01 (needs only two bits) Let us consider the second example 5.1. The binary representation of an integral part is the same. But binary representation of 0.1 is 1/16 + 1/32 + 1/64 + 1/128 ..... and so on until we reach the end of mantissa or sum becomes more than 0.1. In this case, we reach the end of mantissa and therefore the value of 5.1 becomes different in float and double. Tabular difference between Double and Float in Java: DoubleFloat1.It's results are more precised.It's results are less precised.2.To store a variable, it takes 8 bytes and total of 64 bit storage.To store a variable, it takes 4 bytes and total of 32 bit storage.3.It has high range as compared to Float.It has low range when compared with Double.4.Accuracy of Double is more than Float.Accuracy is less compared to Double.5. It uses: 1 bit for sign11 bits for exponent52 bits for mantissa It uses: 1 bit for sign8 bits for exponent23 bits for mantissa Comment More infoAdvertise with us Next Article Comparison of double and float primitive types in Java N Niraj_Pandey Follow Improve Article Tags : Java Java-Data Types Practice Tags : Java Similar Reads Float compareTo() method in Java with examples The comapreTo() method of Float Class is a built-in method in Java that compares the two specified float values. The sign of the integer value returned is the same as that of the integer that would be returned by the function call. Syntax: public int compareTo(Object f) Parameters: The function acce 2 min read Double.compareTo() Method in Java with Examples The Double.compareTo() method is a built-in method in Java of java.lang package. This method is used to compare two Double objects numerically. This method returns 0 if this object is equal to the argument object, it returns less than 0 if this object is numerically less than the argument object, an 3 min read Float compare() Method in Java with Examples The compare() method of Float Class is a built-in method in Java that compares the two specified float values. The sign of the integer value returned is the same as that of the integer that would be returned by the function call. Syntax: public static int compare(float f1, float f2)Parameters: The f 2 min read Double compare() Method in Java with Examples The compare() method of Double Class is a built-in method in Java that compares the two specified double values. The sign of the integer value returned is the same as that of the integer that would be returned by the function call. Syntax: public static int compare(double d1, double d2) Parameters: 2 min read PrintWriter print(float) method in Java with Examples The print(float) method of PrintWriter Class in Java is used to print the specified float value on the stream. This float value is taken as a parameter. Syntax: public void print(float floatValue) Parameters: This method accepts a mandatory parameter floatValue which is the float value to be written 2 min read Like