Is there a better way to convert a wchar_t to float? I've only found one solution that actually works.
wchar_t buf = GetText(); // GetText() returns a wchar_t
float fNumber1 = _wtof(&buf);
I've tried the following as well that fail:
float fNumber1 = (float)GetText(); // returns the ascii code
float fNumber1 = _wtof(&GetText();
float fNumber1 = _wtof(&(GetText()));
#include <wchar.h>
int main ()
{
wchar_t szOrbits[] = L"90613.305 365.24";
wchar_t * pEnd;
long double f1, f2;
f1 = wcstold (szOrbits,&pEnd);
f2 = wcstold (pEnd,NULL);
wprintf (L"Pluto takes %.2Lf years to complete an orbit.\n", f1/f2);
return 0;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.