Jack
2009-11-18 11:37:57 UTC
Hi vc gurus,
template<typename ValueType>
std::string ConvertToString(ValueType value)
{
std::stringstream ss;
ss << value;
return ss.str();
}
With the above code snippet, I am able to
use
str = ConvertToString<DWORD>(temp1);
to obtain a decent string for DWORD numbers.
But it did not succeed with floats
with a number of predefined significant digits.
This is what I wanted to obtain, say,
0.0000001
But the function returns
-3e-006
In normal circumstances, we do
sprintf (buff, "%.6f", number);
How can I turn the above function
into a generic function which can accept
floating point numbers in anyway I want?
Thanks
Jack
template<typename ValueType>
std::string ConvertToString(ValueType value)
{
std::stringstream ss;
ss << value;
return ss.str();
}
With the above code snippet, I am able to
use
str = ConvertToString<DWORD>(temp1);
to obtain a decent string for DWORD numbers.
But it did not succeed with floats
with a number of predefined significant digits.
This is what I wanted to obtain, say,
0.0000001
But the function returns
-3e-006
In normal circumstances, we do
sprintf (buff, "%.6f", number);
How can I turn the above function
into a generic function which can accept
floating point numbers in anyway I want?
Thanks
Jack