如果是在com里面,先把字符串放到一个VARIANT类型的变量里面,然后调用
VariantChangeType, 检查返回的HRESULT.这是最简单的方法.
否则您就要自己写检测代码了,建议用检查字符串是否含有除数字和小数点以外的字符--不过好多边界情况,挺烦的.
VariantChangeType, 检查返回的HRESULT.这是最简单的方法.
否则您就要自己写检测代码了,建议用检查字符串是否含有除数字和小数点以外的字符--不过好多边界情况,挺烦的.
BOOL GGetDoubleFromStr(CString str, int &nPos,double &fValue)
{
char chr;
CString dbstr;
str.Remove(' ');
int l=str.GetLength();
if((nPos+1)>(l-1))return FALSE;
chr=str.GetAt(nPos+1);
BOOL bFirst=TRUE;
while((chr=='+')||(chr=='-')||(chr=='.')||((chr>='0')&&(chr<='9')))
{
if(!bFirst)
{
if(chr=='+' || chr=='-')break;
}
dbstr+=chr;
nPos++;
bFirst=FALSE;
if(nPos+1<l)chr=str.GetAt(nPos+1);else break;
}
if(dbstr.IsEmpty())return FALSE;
fValue=atof(dbstr);
dbstr.Empty();
return TRUE;
}
_isnan()Checks given double-precision floating-point value for not a number (NaN).
Checks given double-precision floating-point value for not a number (NaN).int _isnan( double x );Routine Required Header Compatibility
_isnan <float.h> Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.LibrariesLIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value_isnan returns a nonzero value (TRUE) if the argument x is a NaN; otherwise it returns 0 (FALSE).ParameterxDouble-precision floating-point valueResThe _isnan function tests a given double-precision floating-point value x, returning a nonzero value if x is a NaN. A NaN is generated when the result of a floating-point operation cannot be represented in Institute of Electrical and Electronics Engineers (IEEE) format. For information about how a NaN is represented for output, see printf.Floating-Point Support RoutinesSee Also _finite, _fpclass