Wednesday, November 7, 2007

Leading zeros with C++ printf

To print leading zeros with the format string in printf use the follwing approach:

printf(" %0kd ", number);

where: k is the size of the number.

Eg: to display 0034 with the number 34 use:
printf("%04d", 34);


Anonymous said...

Is there a ruby way of using format strings?

Post a Comment