tags:

views:

278

answers:

4

[win 32 C++]

I don't know how to convert float to LPCWSTR/LPWSTR or LPCWSTR <-> LPWSTR

Thanks a lot

+1  A: 

is there a wsprintf function available?

gbrandt
+4  A: 
#include <sstream>
...
float f = 45.56;
wstringstream wss;
wss << f;
// wss.str().c_str() returns LPCWSTR
cout << wss.str() << endl;
...
Sameer
Or in C via "w" printf variants: http://msdn.microsoft.com/en-us/library/ms647550%28VS.85%29.aspx. I prefer this method though.
James D
+1  A: 

Check out the official MSDN pages for floating point support here and for data conversion here - a bonus link - here's the MSDN page for string functions (including multibyte support).

RobS
A: 

The native Win32 API doesn't have any functions for printing floating point values, but there's a more recent addition called strsafe which has StringCchPrintf

TCHAR buffer[24];
StringCchPrintf(buffer, sizeof(buffer)/sizeof(TCHAR), "%f", float_value);
John Knoeller
Thanks for your comment but it looks complicated and the simple above does same job :)
nXqd