void Cwork::OnChangeshoujia() 
{
UpdateData();
float nVal1, nVal2, nVal3; 
nVal1 = atoi(m_shoujia); 
nVal2 = atoi(m_chengben); 
nVal3 = nVal1 - nVal2; 
m_maoli.Format("%d", nVal3);
UpdateData(false);
}
我想让它可以计算小数,但是这个atoi是转换的int型吧?
有转换成float或者double的么?
我基础比较差,,能不能多告诉我一些类似atoi的类型转换的函数?

解决方案 »

  1.   

    小数就用atof,定义 double对象,然后用
    Format("%.2f")转换
      

  2.   

    atof就行。
    还是一点,为什么不直接定义数值型变量呢??????
      

  3.   

    Convert a string to double. 
    double atof(
       const char *str 
    );
    double _wtof(
       const wchar_t *str 
    );
     MSDN上面都有说明
      

  4.   

    自己去查msdn,还有转换64位的double atof(
       const char *str 
    );
    double _wtof(
       const wchar_t *str 
    );int atoi(
       const char *str 
    );
    int _wtoi(
       const wchar_t *str 
    );
    int _atoi_l(
       const char *str,
       _locale_t locale
    );
    int _wtoi_l(
       const wchar_t *str,
       _locale_t locale
    );long atol(
       const char *str 
    );
    long _atol_l(
       const char *str,
       _locale_t locale
    );
    long _wtol(
       const wchar_t *str 
    );
    long _wtol_l(
       const wchar_t *str,
       _locale_t locale
    );
      

  5.   

    我不是在对话框添加了三个editbox控件么,然后定义了这三个控件的函数,那不直接就是CString了么~还可以定义给EDITBOX控件定义int类型?