C语言如何实现输出浮点数小数点两位(四舍五入法),但若小数点最后位为零则舍去??

2024-11-07 00:31:15
推荐回答(1个)
回答1:

#include
int main()
{float x=12.3456,y=12.344,z=12.303,x1,y1,z1;
x1=((int)((x+0.005)*100))/100.0;
y1=((int)((y+0.005)*100))/100.0;
z1=((int)((z+0.005)*100))/100.0;
printf("x1=%g\n",x1);
printf("y1=%g\n",y1);
printf("z1=%g\n",z1);
return 0; 
}