c - 在 C 程序中使用 '%06.3f'

标签 c printf format-specifiers

#include<stdio.h>

main()
{
    int Fahrenheit;

    for (Fahrenheit = 0; Fahrenheit <= 300; Fahrenheit = Fahrenheit + 20)
        printf("%3d %06.3f\n", Fahrenheit, (5.0/9.0)*(Fahrenheit-32));
}

上述源的输出:

  0 -17.778
 20 -6.667
 40 04.444
 60 15.556
 80 26.667
100 37.778
120 48.889
140 60.000
160 71.111
180 82.222
200 93.333
220 104.444
240 115.556
260 126.667
280 137.778
300 148.889

请解释一下上面程序中‘printf’函数中‘06.3f’的作用。

最佳答案

0左边补0
6 字符串长度应至少为 6 个字符
.3精度为小数点后3位
f 它接受一个float(或double)变量

关于c - 在 C 程序中使用 '%06.3f',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29606309/

相关文章:

C - 打印数组

c - 为什么不采用新的(位宽特定的)printf() 格式选项字符串作为 C99 的一部分?

c++ - 伪代码翻译

我们可以在 c 中对枚举变量进行类型转换吗

c - Linux的C语言中的进程(Ubuntu)

c - 警告 : format ‘%x’ expects argument of type ‘unsigned int’

c - 在预期 PRIu32 的 printf 的格式字符串中使用 %lu 是否有效?

c - os_atomic_or2o 实际上做了什么?

c++ - 我试图将 vsnwprintf 包装在另一个结果奇怪的函数中,它似乎给出了它的地址而不是实际值

c - 在 C 中停止 printf 打印两次运行检查框架?