#include <stdio.h>
int main()
{double d = 1.199;printf("%.2f", d);return 0;
}
输出1.20
如果不想让其四舍五入可以这样:
#include <stdio.h>
#include <math.h>
int main()
{double d = 1.199;printf("%.2f", floor(d * 100) / 100);return 0;
}
ceil(x)返回不小于x的最小整数值(然后转换为double型)。
floor(x)返回不大于x的最大整数值。
round(x)返回x的四舍五入整数值。
摘抄自
https://blog.csdn.net/sunmaoxiang/article/details/83689458