gpt4 book ai didi

C 格式的字符串 - 如何将前导零添加到 float 和 int 值?

转载 作者:太空狗 更新时间:2023-10-29 15:49:01 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Extra leading zeros when printing float using printf?

我试图让这个 C 程序的输出有占位符零,因为这个程序的输出将用作另一个程序的输入。现在,我正在使用以下打印行。

fprintf(fp1, "06 BR%d%d   %3.4f%3.4f%3.4f\n",i,d,X,Y,Z);

i = index for the loop
d = index for a second loop
X = double for a Cartesian system
Y = double for a Cartesian system
Z = double for a Cartesian system

现在输出看起来像这样:

06 BR12   1.00001.00001.0000

我希望它像下面这样:

06 BR0102   001.0000001.0000001.000

我知道我可以手动添加占位符零(如果 i<10,添加一个占位符等)但是有没有比简单地在 if 语句中添加它们更有效的输出占位符零的方法?

提前致谢。

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