Daniel Molina Wegener wrote:
Hello,
How can I pad integral values on double variables with
printf.
I know that %.nf or %.ng sets the precision. But I want to
pad the integral value with zeroes, like 001.023 or 032.012.
Any way to do this with printf?.
#include <stdio.h>
int main(void)
{
double x[] = { 1.023, 32.012 };
size_t i;
printf("[output]\n");
for (i = 0; i < sizeof x / sizeof *x; i++)
printf("%%g: %g, %%f %f, %%.3f %.3f, %%07.3f %07.3f\n",
x[i], x[i], x[i], x[i]);
return 0;
}
[output]
%g: 1.023, %f 1.023000, %.3f 1.023, %07.3f 001.023
%g: 32.012, %f 32.012000, %.3f 32.012, %07.3f 032.012
--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson