Converting long double to CString

3.9k views Asked by At

I am working on C++ MFC project build in unicode settings and I usually use function _ttof to convert CString to double but i couldn't find a function for long double which use TCHAR.

Thanks in advance.

2

There are 2 answers

0
Andrew Komiagin On BEST ANSWER

Use Format method of CString class:

CString sNum;
long double fNum = 10.0;
sNum.Format(_T("%f"), fNum);
0
Bathsheba On

You'll most likely find that for targets that are relevant to Microsoft Foundation Classes, long double and double are the same size.

Therefore you can build your own function stub, (which calls _ttof) with a static assertion sizeof(double) == sizeof(long double) just to be on the safe side:

static_assert(sizeof(double) == sizeof(long double), "double and long double are not the same size");