In C language, %.2f is used to control the output format of floating point numbers, retaining two decimal places after the decimal point. The % in the format specifier indicates the beginning of the format specifier. . separates the integer and decimal parts, and 2 specifies The number of decimal places, f represents a floating point number.
The meaning of %.2f in C language
In C language, %.2f
is a format string used to control the output format of floating point numbers:
Thus, %.2f
tells the printf
or scanf
function to output or input a floating point number in format with two decimal places. Character.
Example:
<code class="c">#include <stdio.h> int main() { float num = 3.141592; printf("浮点数为:%.2f\n", num); return 0; }</code>
The above code will output:
<code>浮点数为:3.14</code>
because it formats the floating point number num
to two digits Decimal output.
The above is the detailed content of What does %.2f mean in C language?. For more information, please follow other related articles on the PHP Chinese website!