//z 2013-10-21 15:01:30 IS2120@BG57IV3 T3345574402.K.F3396121938[T3,L303,R3,V37]
1. atl CString 转换成 double 浮点数
A CString
can convert to an LPCTSTR
, which is basically a const char*
(const wchar_t*
in Unicode builds).
Knowing this, you can use atof()
:
CString thestring("13.37"); double d = atof(thestring).
...or for Unicode builds, _wtof()
:
CString thestring(L"13.37"); double d = _wtof(thestring).
...or to support both Unicode and non-Unicode builds...
CString thestring(_T("13.37")); double d = _tstof(thestring).
(_tstof()
is a macro that expands to either atof()
or _wtof()
based on whether or not_UNICODE
is defined)
//z 2013-10-21 15:01:30 IS2120@BG57IV3 T3345574402.K.F3396121938[T3,L303,R3,V37]
2. 使用 std::stringstream
You can convert anything to anything using a std::stringstream
. The only requirement is that the operators >>
and <<
be implemented. Stringstreams can be found in the <sstream>
header file.
std::stringstream converter; converter << myString; converter >> myDouble;
#include <boost/lexical_cast.hpp> using namespace boost; ... double d = lexical_cast<double>(thestring);
strtod (or wcstod) will convert strings to a double-precision value.
(Requires <stdlib.h>
or <wchar.h>
)
|
|
The moon completes 12.37 orbits per Earth year. |
[email protected] //z 2014-02-20 16:16:02 IS2120@BG57IV3 T707139593 .K.F3153028746[T371,L4620,R198,V6936] void removeTrailingZeros(char pio_cText[]) { char* pCh = strchr(pio_cText,'.'); if(pCh!=NULL) { int iLen = static_cast<int>(strlen(pio_cText)); char* pPos = pio_cText + iLen -1; while(*pPos == '0') { *(pPos--) = '\0'; } if(*pPos == '.') { *pPos= '\0'; } } }[email protected]