I want to convert double to a fixed-width string.
If the width is 10, I want the double value to be rounded to that width.
For example, if value = 102.121323435345 and the width is 10, then this value should be
position ==> 0123456789
value = 102.121323
I can achieve this with snprintf, but I'm looking for my own C ++ code to do the same.
char buf[125]; snprint(buf, width, "%.6f", value);
I tried using below, but it doesnβt help me much,
std::ostringstream oss; oss << std::fixed << std::setw(10) << std::precision(6) << value;
std :: setw guarantees the minimum width for the value, and if the value is larger than the width, it does not round the value.
Thanks.
source share