c中当我保留两位小数时,系统会自动帮我四舍五入,但是我现在不希望这样,怎么解决呢?
先将浮点数乘以100,再转换为int型,再除以100.0(不能是100)就可以了
例如:
float num = 123.5678;
int temp = (int)(num*100);
num = temp/100.0;
a = temp/100.0f - 0.005f;
float a = 1.14645;
int temp = a*100;
a = temp/100.0f;
printf("%.02f\n",a);
http://qa.diyerland.com/questions/2/c