[C] [getting started] the control character problem of printf function

The format description entry of the

printf function is [flag] [output minimum width] [. Precision] [length] Type
if the position of the flag is filled in -, the meaning is "when the data width is less than the minimum width, the result is aligned left and the right is filled in the blanks"
. When I want to implement this function, why fill in 0

on the right?
   
   printf("The bigger number would be %-7f\n", max); //9.27
C
Dec.01,2021

The

C standard requires% f to display at least six significant digits,%-7f, six significant digits plus one decimal point, which happens to fill seven fields
, so I guess your output should be 9.20000

.

if there is a problem with the above answer, correct it as follows:

% f prints all integer parts by default and prints to six digits after the decimal point
so, 9.200000 plus the decimal point has a total of 8 fields, so all the fields are followed by 0, and if the 7 fields are not displayed enough, they are automatically expanded to 8

.

use the g format

 printf("The bigger number would be %-7g\n", max); //9.27
Menu