如果输出一个浮点数
Stemp.Format("%.4f,",x);
这个是输出小数点后4位有效数字. 请问如何能随意设置小数点后面多少位有效果数字
如果我用一个combom来让用户选择输出多少位有效果数字. 1.2.3....
程序不用if语句或switch语句就可以根据用户的选择输出浮点数 

解决方案 »

  1.   

    char fmt[16];sprint(fmt,"%%.%df,",len);//这个len就是用户输入的,%%表示字符'%'Stemp.Format(fmt,x);你的格式化字符串用的格式也是一个字符串,你只要把这个格式处理下就行了比如你的:"%.4f,"就是一个字符串,你组合成自己需要的再传给stemp去用就行了
      

  2.   

    CString strFormat;
    strFormat.Format("%%.%df", nSel+1);// 假定 nSel 从 0 开始
    Stemp.Format(str1,x);
      

  3.   

    Stemp.format("%." + strInput + "f", x)
      

  4.   

    int nCount =0,1,2,3,4,...
    CString strText(_T(""));
    float f = 2.3243253f;
    strText.Format(_T("%.*f"), nCount, f);
    AfxMessageBox(strText);
      

  5.   

    int index=  m_combo.GetCurSel();
    CString m_comboStr = "";
    m_combo.GetLBText(index,m_comboStr);
    CString m_formatStr = "%."+ m_comboStr+"f";//限制输出格式 "%.4f"
    double f = 12345.12345;
    CString str;
    str.Format(m_formatStr,f);
    MessageBox(str);