Home >Backend Development >C++ >The difference between f and lf in C language
In C language, the f format specifier prints the decimal format of a floating-point variable, retaining 6 significant digits after the decimal point; the lf format specifier prints the long decimal format, retaining 12 significant digits after the decimal point.
The difference between f and lf in C language
In C language, f
and lf
are format specifiers used to specify the format used when printing floating-point variables. Their specific differences are as follows:
f
Format specifier
lf
Format specifier
Example
<code class="c">#include <stdio.h> int main() { float value = 3.14159265; printf("f: %.2f\n", value); printf("lf: %.12lf\n", value); return 0; }</code>
Output:
<code>f: 3.14 lf: 3.141592650000</code>
As can be seen from the output:
f
When the format specifier prints floating-point variables, 2 significant digits after the decimal point are retained. lf
format specifier, 12 significant digits after the decimal point are retained. The above is the detailed content of The difference between f and lf in C language. For more information, please follow other related articles on the PHP Chinese website!