سؤال

I'm trying to convert BSTR to float with:

wcstod(data, NULL)

The problem is that this function works ok if data = 239.78, but i receive them in this format data = 239,78.

CComBSTR data = SysAllocString(L"239,78");
cout<<wcstod(data,NUll)<<endl;

Output of this code is 239.

Anyone could help? Thank you.

هل كانت مفيدة؟

المحلول

You should use wcstod_l instead and pass the locale you need as the 3rd argument, so the ',' is understood and parsed properly. Something like this:

_locale_t fr = _create_locale(LC_ALL, "fr-FR"); // french locale
CComBSTR data = SysAllocString(L"239,78");
cout<<wcstod_l(data, NULL, fr)<<endl;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top