int main ()
{
    float Num = 3254.4;
    printf("%06.4f",Num);
    return 0;
}

为什么它不按我的期望打印003254.3999,而是3254.3999

张贴前I've completely read this reference

最佳答案

根据您的引用:

宽度:

最少要打印的字符数。如果要打印的值小于此数字,则结果将用空格填充。即使结果较大,该值也不会被截断。

请注意,这会计算包括在内的所有字符。和小数点后四位

左边6 +右边4 + 1(代表小数)= 11 (不是10)

您想要的是“%011.4f”

测试了这个:

printf("%011.4f\n", 1.4);

结果是:
000001.4000  // note 6 to the left and 4 to the right (plus the .) = 11

关于c - printf中的子说明符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20665173/

10-11 19:13