Double to CString including the fractional part :- --------------------------------------------------CString strValue,strInt, strDecimal; int decimal,sign; double dValue = 4.125; strValue = _fcvt(dValue,6,&decimal,&sign); // Now decimal contains 1 because there is only one digit before the . strInt = strValue.Left(decimal); // strInt contains 4 strDecimal = strValue.Mid(decimal); // strDecimal contains 125CString strFinalVal; strFinalVal.Format("%s.%s",strInt,strDecimal); // strFinalVal contains 4.125 Double To CString :- -------------------- CString strValue; int decimal,sign;double dValue = 123456789101112; strValue = _ecvt(dValue,15,&decimal,&sign); // Converting double to string
CString.left——获得指定的长度
呵呵
我帮你看看!注明帖子的URL!
发什么东西给你?
--------------------------------------------------CString strValue,strInt, strDecimal;
int decimal,sign;
double dValue = 4.125;
strValue = _fcvt(dValue,6,&decimal,&sign); // Now decimal contains 1 because there is only one digit before the .
strInt = strValue.Left(decimal); // strInt contains 4
strDecimal = strValue.Mid(decimal); // strDecimal contains 125CString strFinalVal;
strFinalVal.Format("%s.%s",strInt,strDecimal); // strFinalVal contains 4.125
Double To CString :-
--------------------
CString strValue;
int decimal,sign;double dValue = 123456789101112;
strValue = _ecvt(dValue,15,&decimal,&sign); // Converting double to string
sprintf(szOut,"%.3g",f)是可以,不过对于f=999。99999不行,会进位,变成1e+003
char a[4];
float ft = 99.999;
sprintf(a,"%f",ft);
a[4] = 0;
float ft = 99.999;
sprintf(a,"%.3f",ft);
a[4] = 0;
::sprintf(buff,"%.2f",a);
double b = 1.11111111;
double c = 99.999999;
char buff[255];
::sprintf(buff,"%ld",(long)a);//999.999999->"999"
//下面两行为99.9999999->"99.9"
::sprintf(buff,"%f",c);//
buff[4] = 0;
::sprintf(buff,"%.2f",b);//1.11111111->"1.11"
兄弟,你这样我不是还要先判断要转换的float究竟是a类型还是b类型还是c类型???况且我需要的是一条语句。目前我用两条,这么做的:
sprintf(szOut,"%f",f);
szOut[f<100?4:3]=NULL;
GetNumberFormat
typedef struct _numberfmt {
UINT NumDigits;
UINT LeadingZero;
UINT Grouping;
LPTSTR lpDecimalSep;
LPTSTR lpThousandSep;
UINT NegativeOrder;
} NUMBERFMT, *LPNUMBERFMT;结构中,要制定NumDigits就是小数位数。我的要求里面小数位数是不定的,我是要有效数字的大小是固定的。看看再。实在不行只好sprintf(szOut,"%f",f);szOut[f<100?4:3]=NULL;了。////////////////////////
如果是444444.222呢?
结果是什么?
///////////////////////
我前面已经说过,浮点数的大小已经被限制在0到1000之间了。