I want to remove trailing zeros from doubles whilst they're being converted to a string. For example, 0.9345750000 => 0.934575 and 0.6 => 0.6
I'm currently using this:
std::stringstream ss;
ss << std::setprecision(15) << std::noshowpoint << value;
std::string num = ss.str();
but it's converting 0.00001 to 1e-05.
So, I added std::fixed
:
std::stringstream ss;
ss << std::fixed << std::setprecision(15) << std::noshowpoint << value;
std::string num = ss.str();
but now 0.9345750000 appears as 0.9345750000, i.e. the trailing zeros haven't been removed.
How can I convert a double to string, regardless of how many decimal places it has, prevent scientific notation, whilst still removing trailing zeros?