c - printf 中的子说明符

标签 c printf mingw32

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/

相关文章:

c - 在 Windows 上用 C 搜索文件

c - 在 C 中打印格式化字符串

c - Sprintf 关于格式化的警告

c++ - 将项目与静态构建 curl 链接

c++ - 类型转换与 memcpy() : which one is better?

c - 如何在C中序列化数据

c - 声明的含义

创建函数重复字符

mingw - 如何在 Linux 或 MacOS 上同时安装 mingw32 和 mingw64?

git - 为什么我收到错误 "fatal: ' C :/Program Files (x86)/Git' is outside the repository"when I run "git reset --hard ~1" from within the repository?