gpt4 book ai didi

c - printf 中的子说明符

转载 作者:太空狗 更新时间:2023-10-29 14:55:02 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com