Difference between float and double in C/C++ Last Updated : 23 Jun, 2023 Comments Improve Suggest changes Like Article Like Report To represent floating point numbers, we use float, double, and long double. What's the difference? double has 2x more precision than float. float is a 32-bit IEEE 754 single precision Floating Point Number - 1 bit for the sign, 8 bits for the exponent, and 23* for the value. float has 7 decimal digits of precision. double is a 64-bit IEEE 754 double precision Floating Point Number - 1 bit for the sign, 11 bits for the exponent, and 52* bits for the value. double has 15 decimal digits of precision. Let's take an example: For a quadratic equation x^2 - 4.0000000 x + 3.9999999 = 0, the exact roots to 10 significant digits are, r1 = 2.000316228 and r2 = 1.999683772. Notice the difference in using float and double. C++ // C program to demonstrate // double and float precision values #include <math.h> #include <stdio.h> // utility function which calculate roots of // quadratic equation using double values void double_solve(double a, double b, double c) { double d = b * b - 4.0 * a * c; double sd = sqrt(d); double r1 = (-b + sd) / (2.0 * a); double r2 = (-b - sd) / (2.0 * a); printf(" % .5f\t % .5f\n ", r1, r2); } // utility function which calculate roots of // quadratic equation using float values void float_solve(float a, float b, float c) { float d = b * b - 4.0f * a * c; float sd = sqrtf(d); float r1 = (-b + sd) / (2.0f * a); float r2 = (-b - sd) / (2.0f * a); printf(" % .5f\t % .5f\n ", r1, r2); } // driver program int main() { float fa = 1.0f; float fb = -4.0000000f; float fc = 3.9999999f; double da = 1.0; double db = -4.0000000; double dc = 3.9999999; printf("roots of equation x^2- 4.0000000 x + 3.9999999= " "0 are: \n "); printf("for float values: \n"); float_solve(fa, fb, fc); printf("for double values: \n"); double_solve(da, db, dc); return 0; } Outputroots of equation x2- 4.0000000 x + 3.9999999= 0 are: for float values: 2.00000 2.00000 for double values: 2.00032 1.99968 Complexity AnalysisThe time complexity of the given code is O(1) The auxiliary space complexity of the code is also O(1)Difference between float and double Let us see the differences in a tabular form that is as follows: float double Its size is 4 bytesIts size is 8 bytesIt has 7 decimal digits precisionIt has 15 decimal digits precisionIt is an integer data type but with decimalsIt is an integer data type but with decimalsIt may get Precision errors while dealing with large numbersIt will not get precision errors while dealing with large numbers.This data type supports up to 7 digits of storage.This data type supports up to 15 digits of storage.For float data type, the format specifier is %f.For double data type, the format specifier is %lf.For example -: 3.1415For example -: 5.3645803It is less costly in terms of memory usage.It is costly in terms of memory usage.It requires less memory space as compared to double data type.It needs more resources such as occupying more memory space in comparison to float data type.It is suitable in graphics libraries for greater processing power because of its small range.It is suitable to use in the programming language to prevent errors while rounding off the decimal values because of its wide range. Comment More infoAdvertise with us Next Article Difference between float and double in C/C++ M Mandeep Singh Improve Article Tags : Difference Between C Language C++ cpp-data-types C-Data Types +1 More Practice Tags : CPP Similar Reads Difference Between Constants and Variables in C The constants and variables in C are both used to store data. So it is essential to know the difference between the variables and constants in C so that we can decide which one to use based on the situation. In this article, we will discuss the basic difference between a constant and a variable in C 3 min read Difference between data type and data structure Data Type A data type is the most basic and the most common classification of data. It is this through which the compiler gets to know the form or the type of information that will be used throughout the code. So basically data type is a type of information transmitted between the programmer and the 4 min read C Float and Double Float and double are two primitive data types in C programming that are used to store decimal values. They both store floating point numbers but they differ in the level of precision to which they can store the values.In this article, we will study each of them in detail, their memory representation 5 min read Difference between fundamental data types and derived data types In computer programming, data type is a classification that specifies to compiler or interpreter which type of data user is intending to use. There are two types of data types - Primitive/Fundamental data type: Each variable in C/C++ has an associated data type. Each data type requires different amo 8 min read Write a program that produces different results in C and C++ Write a program that compiles and runs both in C and C++, but produces different results when compiled by C and C++ compilers. There can be many such programs, following are some of them. 1) Character literals are treated differently in C and C++. In C character literals like 'a', 'b', ..etc are tre 2 min read Like