float a = 0.01;
float b = 1;
int   c = (int)(a*100);//我watch等号右边的值是1没错,那就是我想要的
结果c=0;
float a = 0.02;
float b = 1;
int   c = (int)(a*100);//我watch等号右边的值是2没错,那就是我想要的
结果c=1

解决方案 »

  1.   

    #include "math.h"
    int   c = (int)floor(a*100);//
      

  2.   

    int   c = (int)((a*100)+0.5);
      

  3.   

    这一点都不奇怪,浮点数都有个精度问题,1有时存储的是.999999999999之类的,double a = 0.01;
    int   c = (int)(a*100 + 1e-10 );其中1e-10改成你所允许的精度。
      

  4.   


    你float-->int 类型转换错误,转换总是朝表达数据能力强的方向进行。
      

  5.   

    呵呵,那怎么实现这个简单功能?
    我想取任意一个float数的小数点后的2位值,比如1.234,我要值1.230
    有没有这样的库函数?如果没有该怎么做?