How to automatically fill 0 c language before the number

Disclaimer: This article is a blogger original article, welcome to reprint, please indicate the source. https://blog.csdn.net/Think88666/article/details/90287355

When we need to format time format will be used this

int a=1;

printf("a=%04d\n", a);

//输出6位十进制整数 左边补0,显示 a=0001

  This example refers to 0% 04d of the leading zero mass, representative of 4 bit width. Generally these two must be together. Of course, when a length longer than the width numbers alone, then this does not work, such as a = 12345; the output is a = 12345

Guess you like

Origin blog.csdn.net/Think88666/article/details/90287355