float 类型变量想精准两位 可是直接打印可以 赋给变量就不行了 帮忙看看怎么解决
#include <stdio.h>float fun ( float h )
{
float c;
c = (int)(h*100+0.5)/100.0;
printf("inner_:%f\n",(int)(h*100+0.5)/100.0);//结果是2021.990000
printf("inner:%f\n",c);//结果是2021.989900
return c;
}
int main(){
float a = 2021.9899;
printf("%f\n",fun(a));
printf("outer:%f\n",(int)(a*100+0.5)/100.0);
return 0;
}