Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
想知道我是否做了类似的事情
printf("%04.2f", float_variable);
我可以打印吗
" 1.15"
代替
"01.15"
我知道奇怪的要求,但这是我需要的。不知道如何开始。
只需删除0,根据定义,这意味着数字将被零填充:
0
printf("%5.2f", float_variable);
请注意,字段的宽度是 5 而不是 4,因为该值等于整个输出字符串的最小宽度,而不仅仅是位数。