C99 standard stipulates that %f is used to output double type, and %lf is equivalent to %f (you can add lowercase letter L between "%"and letters to indicate that the output is long type).
The sample code is as follows:
%g outputs the output value with a shorter output length in %e or %f type.
Extended data:
You can insert a number between "%"and letters to indicate the maximum field width. For example, %9.2f represents a floating-point number with an output field width of 9, where the decimal place is 2, the integer place is 0, and the decimal point occupies one place, which is not enough to align 9 places to the right.
If the length or integer digits of the string exceed the specified field width, it will be output according to its actual length. But for floating-point numbers, if the number of bits in the integer part exceeds the specified integer bit width, it is output according to the actual integer bit; If the number of decimal places exceeds the width of decimal places in the description, the output will be rounded according to the width of the description.
If floating-point numbers are used to represent the output format of characters or integers, the number after the decimal point indicates the maximum width, and the number before the decimal point indicates the minimum width. For example, %6.9s means to display a string with a length of not less than 6 and not more than 9; If it is greater than 9, the content after the ninth character will be deleted.
References:
Baidu Encyclopedia -printf () function