请问各位高手,在VC++中如何获得浮点数的小数部分和整数部分???!!!!急用!!!

解决方案 »

  1.   

    float n=12.223;int i=(int)n;float x=n-(float)i;
      

  2.   

    先转成str,例如ftoa
    再在str中找到'.'
    然后把两边的值取出来转成你要的类型,例如atoi
      

  3.   

    float n=12.223;
    改为
    float n=12.223f;少加了个f
      

  4.   

    float fVal=100.323;
    float fDecimal;
    int iInteger;iInteger = (fVal * 10) / 10;
    fDecimal = fVal - iInteger;
      

  5.   

    在micosoft vc++中
    double mDouble=1098.9875;
    double Dec=Dec-(int)mDouble;
    if(Dec<0)
    Dec+=1;
      

  6.   

    应该是double Dec=mDouble-(int)mDouble;
    写错了:)
      

  7.   

    #include <math.h>
    #include <iostream.h>
    int main(int argc, char* argv[])
    {
    double f1 = 3.4563f;
    double f_int,f_float;
    f_float = (float)modf(f1, &f_int);
    cout<<"Integer is:"<<f_int<<endl;
    cout<<"Float is:"<<f_float<<endl;
    return 0;
    }
      

  8.   

    double dbl = 3.1415926;
    int nDec = (int)dbl;
    double dblDec = dbl - nDec;
      

  9.   

    转化成Cstring型,再一个一个字母的取出来肯定不会错!
      

  10.   

    反正我以前用float i=1.888;
                   int a=int(1.888);
                   float b=i-a;
          这样蛮容易用的.