浮点值的格式说明符的一般形式如下:
%[width][.precision][modifier]f
方括号代表可选规范。
可以省略width
或.precision
或modifier
或这些的任意组合。width
值是一个整数,指定包含空格的字符总数。precision
值是一个整数,指定小数点后的小数位数。
当输出的值是long double
类型时,修饰符部分为L,否则省略它。
#include <stdio.h>
int main(void)
{
float total_length = 10.0f; // In feet
float count = 4.0f; // Number of equal pieces
float piece_length = 0.0f; // Length of a piece in feet
piece_length = total_length/count;
printf(%f feet %f pieces %f feet.\n,total_length, count, piece_length);
printf(%8.2f foot %5.0f pieces %6.2f feet.\n,total_length, count, piece_length);
return 0;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。