printf format specifier

06 Jan 2011 . Edited: 06 Jan 2011

Hello C-Programmers,

maybe i´m only a little bit stupid, but i try to ask anyway.

If i have a printf like this:

...

printf ("%08.6f", 3.1415);

...

i understand and expected, that "00000003.141500" should be displayed. In mycase only "3.141500" is displayed.

Is my expectation wrong? Did i make an error in the format specifier?

Or is the "08" format specifier specifying the maximum of digits which can be used but not must be used? If yes, why then after the coma, there are 6 digits filled?

Kind Regards

Erwin

06 Jan 2011

Hi,

after some more trials i myself found the solution. the "08" specifies the maximum number of digits before _and_ after the coma which are used for the output string. So if i put "%015.6f", 8 digits befor the coma (filled with zeros) before the coma are used and the 6 digits after the coma. Together there are 15 digits used including the coma.

Sorry for the stupid question!

Erwin