double value = 02369.000133699;//acutally stored as 2369.000133698999900
const std::uint32_t left = std::uint32_t(std::abs(value) < 1 ? 1: (1 + std::log10(std::abs(value))));
std::ostringstream out;
out << std::setprecision(std::numeric_limits<T>::digits10 - left ) << std::fixed << value;
std::string str = out.str(); //str = "2369.00013369900"
std::ostringstream out2;
out2 << std::setprecision(std::numeric_limits<T>::digits10 ) << std::fixed << value;
std::string str2 = out2.str(); // str2 = "2369.000133698999900"
I'm wondering how std::stringstream/precision works for formatting floating-point number.
It seems that if precision argument is superior to 16
minus number of non-fractional digits, this lead to a formatting of form "2369.000133698999900"
instead of a "nice" "2369.00013369900"
how std::stringstream
know that 8999900
must be resume to one 9
even if I don"t tell it to do the rounding on the 8
(like passing 12
as argument to the setprecision
function) ?but don't do it for argument superior to 12