Mar*_*ean 10 c format printf width
我知道0在占位符的宽度之前放置任意数量的实现零填充.例如,printf("%02d", 6);打印06.
0
printf("%02d", 6);
06
但是0在占位符的精度之前放一个单一的呢?例如,对于两个printf("%0.2lf", 0.123);和printf("%.2lf", 0.123);,输出0.12.
printf("%0.2lf", 0.123);
printf("%.2lf", 0.123);
0.12
如果它什么都不做,是否有首选格式?
Mat*_*son 10
它们是"等同的".如果您使用"%07.2",那么通过在前面添加额外的零来实现差异.
编辑:最初有"%04.2",这当然没有任何区别,因为一个带有两位小数的浮点数总是4宽.
a3.*_*ity 6
%3.2f //(print as a floating point at least 3 wide and a precision of 2) %0.2lf //(print as a floating point at least 0 wide and a precision of 2) %.2lf //(print as a floating point at least 0(default) wide and a precision of 2)
%3.2f //(print as a floating point at least 3 wide and a precision of 2)
%0.2lf //(print as a floating point at least 0 wide and a precision of 2)
%.2lf //(print as a floating point at least 0(default) wide and a precision of 2)
归档时间:
12 年,9 月 前
查看次数:
37247 次
最近记录:
7 年,11 月 前