RFC: 6178739 - Formatter - Zero padding flag with zero width

David DeHaven david.dehaven at oracle.com
Thu Jun 27 05:55:39 UTC 2013


>> Specifically, I was referred to how C handles "%0.4f\n".

No width, decimal truncated (rounded? floored? I forgot which it is) to four digits.

-DrD-


>>    printf("%0.4f\n", 56789.456789F);
...
>> 56789.4570
>   ^ ^ ^ ^ ^ ^ ^ ^
...
> "A leading zero in the width value is interpreted as the zero-padding flag mentioned above […]."

Only if there's a valid width following, which there isn't in the case above. Try "%016.4" with the above test. Note that the width is the *full* width of the entire field, including decimal point and following digits.

printf("%016.4f\n", 56789.456789F);
printf("%0.4f\n", 56789.456789F);

Produces:
00000056789.4570
56789.4570

-DrD-




More information about the core-libs-dev mailing list