I need to format a double. I use the code bellow
wstring to_wstring1(double f){
wchar_t wc[0x40];swprintf(wc,countof(wc),L"%E",f);return wstring(wc);
}
Is there a way to do it that avoids using the buffer wc? I am thinking to allocate a wstring with the size of the buffer and write there and after resize the string up to the final 0. Is there a simpler way?
You can use std::to_wstring(double).
Note: It does require C++11
Something like this?
#include <iostream>
#include <sstream>
int main() {
std::wostringstream w;
w << 1.0;;
std::wcout << w.str() << std::endl;
}
Note: It does not require C++11
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With