As it says there: twice the size. A double typically takes up 64 bits of memory, and a float only 32. Answer from Updatebjarni on reddit.com
🌐
GeeksforGeeks
geeksforgeeks.org › c language › c-float-and-double
C Float and Double - GeeksforGeeks
July 23, 2025 - From above, 65.5 = 1.000001001 x 106 Normalized Mantissa = 000001001 Now, according to the standard, bais is 1023. So, = 1023 + 6 = 1029 Baised exponent = 10000000101 And the signed bit is 0 (positive) So, the IEEE 754 representation of 65.125 is, 0 10000000101 0000010010000000000000000000000000000000000000000000 · In conclusion, C uses both float and double for decimal numbers, but they vary in terms of precision, memory usage, range, and speed.
🌐
Wikipedia
en.wikipedia.org › wiki › C_data_types
C data types - Wikipedia
3 weeks ago - The C language provides basic ... syntax to build array and compound types. The C standard library contains additional definitions of support types, that have additional properties, such as providing storage with an exact size, independent of the language implementation on specific hardware platforms. The C language provides the four basic arithmetic type specifiers char, int, float and double (as well as ...
People also ask

How do you use double for scientific notation in C?
You can represent numbers in scientific notation with double by using the e notation. For example, double value = 1.23e4; represents 1.23 × 10^4.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › double in c
Everything You Need to Know About the Double Data Type in C
Can double be used to store large numbers in C?
Yes, double is capable of storing large numbers, but it has a finite precision. Numbers beyond its range can result in overflow or underflow.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › double in c
Everything You Need to Know About the Double Data Type in C
How do I round a double value to the nearest integer in C?
Use the round() function from the math.h library to round a double to the nearest integer value. For example, double rounded = round(3.6);.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › double in c
Everything You Need to Know About the Double Data Type in C
🌐
Reddit
reddit.com › r/learnprogramming › what does it mean in c that data type "double" is more "expensive" than data type "float"
r/learnprogramming on Reddit: What does it mean in C that data type "Double" is more "expensive" than data type "Float"
December 6, 2021 -

I was wondering why you wouldn't just use a double all the time instead of a float. I googled and found this as an explanation:

Double is more precise than float and can store 64 bits; double the number of bits float can store. We prefer double over float if we need to do precision up to 15 or 16 decimal points; otherwise, we can stick to float in most applications, as double is more expensive.

Difference between float and double in C/C++ | Coding Ninjas Blog

Can anyone clarify what being "more expensive" means in this context?

Top answer
1 of 3
70

To quote the C++ standard, §3.9.1 ¶8:

There are three floating point types: float, double, and long double. The type double provides at least as much precision as float, and the type long double provides at least as much precision as double. The set of values of the type float is a subset of the set of values of the type double; the set of values of the type double is a subset of the set of values of the type long double. The value representation of floating-point types is implementation-defined. Integral and floating types are collectively called arithmetic types. Specializations of the standard template std::numeric_limits (18.3) shall specify the maximum and minimum values of each arithmetic type for an implementation.

That is to say that double takes at least as much memory for its representation as float and long double at least as much as double. That extra memory is used for more precise representation of a number.

On x86 systems, float is typically 4 bytes long and can store numbers as large as about 3×10³⁸ and about as small as 1.4×10⁻⁴⁵. It is an IEEE 754 single-precision number that stores about 7 decimal digits of a fractional number.

Also on x86 systems, double is 8 bytes long and can store numbers in the IEEE 754 double-precision format, which has a much larger range and stores numbers with more precision, about 15 decimal digits. On some other platforms, double may not be 8 bytes long and may indeed be the same as a single-precision float.

The standard only requires that long double is at least as precise as double, so some compilers will simply treat long double as if it is the same as double. But, on most x86 chips, the 10-byte extended precision format 80-bit number is available through the CPU's floating-point unit, which provides even more precision than 64-bit double, with about 21 decimal digits of precision.

Some compilers instead support a 16-byte (128-bit) IEEE 754 quadruple precision number format with yet more precise representations and a larger range.

2 of 3
22

It depends on your compiler but the following code can show you the number of bytes that each type requires:

int main() { 
    printf("%d\n", sizeof(double)); // some compilers print 8
    printf("%d\n", sizeof(long double)); // some compilers print 16
    return 0;
}
🌐
Scaler
scaler.com › home › topics › what is double in c?
What is Double in C? - Scaler Topics
April 28, 2024 - It is used to store large values of decimal numbers. Values that are stored are double the size of data that can be stored in the float data type.
🌐
Log2Base2
log2base2.com › c-questions › io › how-to-print-double-value-in-c.html
how to print double value in c
We can print the double value using both %f and %lf format specifier because printf treats both float and double are same. So, we can use both %f and %lf to print a double value.
🌐
TutorialsPoint
tutorialspoint.com › float-and-double-in-c
Float and Double in C
Here is an example of float in C language, Live Demo · #include<stdio.h> #include<string.h> int main() { float x = 10.327; int y = 28; printf("The float value : %f ", x); printf("The sum of float and int variable : %f ", (x+y)); return 0; } The float value : 10.327000 The sum of float and int variable : 38.327000 · Double is also a datatype which is used to represent the floating point numbers.
Find elsewhere
🌐
Global Tech Council
globaltechcouncil.org › home › what is double in c?
What is Double in C? - Global Tech Council
May 30, 2025 - In C programming, “double” refers to a type of data that can hold numbers with decimal points, such as 3.14 or 0.01. It’s called “double” because it has double the precision compared to a “float,” another data type for decimals.
🌐
Wikipedia
en.wikipedia.org › wiki › Long_double
long double - Wikipedia
1 week ago - On the x86 architecture, most C compilers implement long double as the 80-bit extended precision type supported by x86 hardware (generally stored as 12 or 16 bytes to maintain data structure alignment), as specified in the C99 / C11 standards (IEC 60559 floating-point arithmetic (Annex F)).
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › double in c
Everything You Need to Know About the Double Data Type in C
February 27, 2025 - The student assumes full responsibility ... . Read More ... Double in C is used to store real numbers (decimal values) that require more precision and a larger range than regular floating-point numbers....
Top answer
1 of 3
65

For variable argument functions like printf and scanf, the arguments are promoted, for example, any smaller integer types are promoted to int, float is promoted to double.

scanf takes parameters of pointers, so the promotion rule takes no effect. It must use %f for float* and %lf for double*.

printf will never see a float argument, float is always promoted to double. The format specifier is %f. But C99 also says %lf is the same as %f in printf:

C99 §7.19.6.1 The fprintf function

l (ell) Specifies that a following d, i, o, u, x, or X conversion specifier applies to a long int or unsigned long int argument; that a following n conversion specifier applies to a pointer to a long int argument; that a following c conversion specifier applies to a wint_t argument; that a following s conversion specifier applies to a pointer to a wchar_t argument; or has no effect on a following a, A, e, E, f, F, g, or G conversion specifier.

2 of 3
13

When a float is passed to printf, it is automatically converted to a double. This is part of the default argument promotions, which apply to functions that have a variable parameter list (containing ...), largely for historical reasons. Therefore, the “natural” specifier for a float, %f, must work with a double argument. So the %f and %lf specifiers for printf are the same; they both take a double value.

When scanf is called, pointers are passed, not direct values. A pointer to float is not converted to a pointer to double (this could not work since the pointed-to object cannot change when you change the pointer type). So, for scanf, the argument for %f must be a pointer to float, and the argument for %lf must be a pointer to double.

🌐
W3Schools
w3schools.com › c › ref_keyword_double.php
C double Keyword
The double keyword is a data type which stores fractional numbers. It is usually 64 bits (8 bytes) long, and it can store positive and negative numbers with values between 1.7e−308 and 1.7e+308. Read more about data types in our C Data Types Tutorial. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com
🌐
GeeksforGeeks
geeksforgeeks.org › c language › convert-a-char-array-to-double-in-c
Convert a Char Array to Double in C - GeeksforGeeks
May 21, 2023 - Here, str is the string to be converted to a double-precision floating-point number, and endptr is a pointer to a character pointer. endptr is used to store the pointer to the first character after the numeric value in the string. If str does not contain a valid floating-point number, then endptr is set to str.
🌐
Javatpoint
javatpoint.com › what-is-double-in-c
What is double in C - javatpoint
How to use Pointers in C language · What is a Storage Class in C · What is short int in C · Insertion Sort in C · Queue in C · Segmentation Fault in C · FUNCTION PROTOTYPE IN C · Iteration in C · One dimensional array in C · Overview of Structures and Unions in C · Difference between 1D and 2D array in C · Differences between Float and Double in C ·
🌐
ThoughtCo
thoughtco.com › definition-of-double-958065
What Is a Double in C, C++ and C# Programming?
April 27, 2019 - The double is a fundamental data type built into the compiler and used to define numeric variables holding numbers with decimal points. C, C++, C# and many other programming languages recognize the double as a type. A double type can represent fractional as well as whole values.
🌐
Programiz
programiz.com › c-programming › c-data-types
C Data Types
And, it can take 232 distinct states from -2147483648 to 2147483647. ... In C, floating-point numbers can also be represented in exponential. For example, ... The size of float (single precision float data type) is 4 bytes. And the size of double (double precision float data type) is 8 bytes.
Top answer
1 of 5
813

"%f" is the (or at least one) correct format for a double. There is no format for a float, because if you attempt to pass a float to printf, it'll be promoted to double before printf receives it1. "%lf" is also acceptable under the current standard -- the l is specified as having no effect if followed by the f conversion specifier (among others).

Note that this is one place that printf format strings differ substantially from scanf (and fscanf, etc.) format strings. For output, you're passing a value, which will be promoted from float to double when passed as a variadic parameter. For input you're passing a pointer, which is not promoted, so you have to tell scanf whether you want to read a float or a double, so for scanf, %f means you want to read a float and %lf means you want to read a double (and, for what it's worth, for a long double, you use %Lf for either printf or scanf).


1. C99, §6.5.2.2/6: "If the expression that denotes the called function has a type that does not include a prototype, the integer promotions are performed on each argument, and arguments that have type float are promoted to double. These are called the default argument promotions." In C++ the wording is somewhat different (e.g., it doesn't use the word "prototype") but the effect is the same: all the variadic parameters undergo default promotions before they're received by the function.

2 of 5
66

Given the C99 standard (namely, the N1256 draft), the rules depend on the function kind: fprintf (printf, sprintf, ...) or scanf.

Here are relevant parts extracted:

Foreword

This second edition cancels and replaces the first edition, ISO/IEC 9899:1990, as amended and corrected by ISO/IEC 9899/COR1:1994, ISO/IEC 9899/AMD1:1995, and ISO/IEC 9899/COR2:1996. Major changes from the previous edition include:

  • %lf conversion specifier allowed in printf

7.19.6.1 The fprintf function

7 The length modifiers and their meanings are:

l (ell) Specifies that (...) has no effect on a following a, A, e, E, f, F, g, or G conversion specifier.

L Specifies that a following a, A, e, E, f, F, g, or G conversion specifier applies to a long double argument.

The same rules specified for fprintf apply for printf, sprintf and similar functions.

7.19.6.2 The fscanf function

11 The length modifiers and their meanings are:

l (ell) Specifies that (...) that a following a, A, e, E, f, F, g, or G conversion specifier applies to an argument with type pointer to double;

L Specifies that a following a, A, e, E, f, F, g, or G conversion specifier applies to an argument with type pointer to long double.

12 The conversion specifiers and their meanings are: a,e,f,g Matches an optionally signed floating-point number, (...)

14 The conversion specifiers A, E, F, G, and X are also valid and behave the same as, respectively, a, e, f, g, and x.

The long story short, for fprintf the following specifiers and corresponding types are specified:

  • %f -> double
  • %Lf -> long double.

and for fscanf it is:

  • %f -> float
  • %lf -> double
  • %Lf -> long double.