求教CString.Format()的用法

来源:百度知道 编辑:UC知道 时间:2024/05/20 10:08:16
我现在的程序是
int a = 21;
double b = 3.45;
CString str;
str.Format("%03d%02.4f" , a , b);
现在得到的结果是"0213.4500"
%02.4f对b的整数部分不起作用
我想要得到一个形如aaabb.bbbb的字符串("02103.4500"),如果a不足3位,用0补齐,如果b的整数和小数不足2位和4位也要用0补齐
第二位仁兄,我已经用GetLength和Insert做好了,就是想问一问有没有格式化输入可以一句搞定的

帮你搞定了,自己理解理解:
int a = 21;
double b = 3.45;

CString str1;
str1.Format("%d",a);
if(str1.GetLength() == 1)
str1 = "00" + str1;
else if(str1.GetLength() == 2)
str1 = "0" + str1;

CString str2;
str2.Format("%.4f",b);
int pos = str2.Find(".");
CString str3 = str2.Left(pos);
if(str3.GetLength() == 1)
str2.Format("0%.4f",b);

CString Allstr;
Allstr = str1 + str2;

%02.4f好象不合要求,收藏,等待高人回答