I have a CString variable which I need to convert into double
CString sVal(_T(" 4.2"));
double dbl2 = _wtof(sVal);
And I got dbl2 = 4.0000 instead of 4.2. What could be the reason for the rounding?
decimal point is one of the "items" in localization
WARNING!!! below code is not optimized for many subsequent conversions
#include <locale.h>
#include <string>
...
CString sVal(_T(" 4.2"));
std::string currentLocale = setlocale(LC_NUMERIC, NULL); //retrive current locale
setlocale(LC_NUMERIC, "C"); //change numeric locale to C, now decimal separator is '.'
double dbl2 = _wtof(sVal);
setlocale(LC_NUMERIC, currentLocale.c_str()); //return to original locale