c - printf中的 "%.6d"是什么意思

%.6d是什么意思:

printf("%s.%.6d len:%d ", timestr, header->ts.tv_usec, header->len);

是不是打错字了?

看来 %.6d%6d 是一样的。

最佳答案

%.6d

In the .precision format for integer specifiers (d, i, o, u, x, X), precision specifies the minimum number of digits to be written. If the value to be written is shorter than this number, the result is padded with leading zeros. The value is not truncated even if the result is longer.

%6d

The width (here 6) specifies the minimum number of characters to be printed. If the value to be printed is shorter than this number, the result is padded with blank spaces. The value is not truncated even if the result is larger.

例子:

printf("%.6d\n%6d",1,1);

输出:

000001
     1

https://stackoverflow.com/questions/2778785/

相关文章:

c++ - 如何将小数点分隔符设置为逗号?

emacs - Emacs 中的 LaTeX 缩进(格式化)

php - 将价格格式化为逗号分隔

java - 自动将大括号添加到 java 代码库中的所有 if/else/for/while 等

c# - 将 TimeSpan 格式化为 mm :ss for positive and negat

javascript - 如何在 JavaScript 中为数字添加千位分隔符?

javascript - 以编程方式格式化谷歌图表

latex - 如何更改 Latex 中图形的标题?

javascript - 使用 1.5K、1M、1G 等公制前缀格式化 javascript 数字

r - 增加 R 中箱线图名称的大小