%.21f is the format string of floating point numbers in C language, which means: 21 digits are retained after the decimal point, for example: float num = 123.456789; printf("%.21f", num); // Output: 123.456789012345678901
The meaning of %.21f in C language
%.21f
It is a format string in C language, used to control the output of floating point numbers. It means:
%
: This is the starting identifier of the format specifier. .
: This is a decimal point symbol, indicating that a decimal point should be displayed in the output. 21
: This is the number of digits to be displayed after the decimal point. f
: This is a floating point numeric character, indicating that a floating point number is to be output. Thus, %.21f
formats a floating point number into a string retaining 21 digits after the decimal point. For example:
<code class="c">float num = 123.456789; printf("%.21f", num); // 输出:123.456789012345678901</code>
In the above example, the printf()
function formats the floating point number num
into a string with 21 digits after the decimal point, and which prints to the console.
It’s worth noting:
The above is the detailed content of What does %.21f mean in C language?. For more information, please follow other related articles on the PHP Chinese website!