Search code examples
c++type-conversionscientific-notationostringstream

How to turn off scientific notation for double when appending it to ostringstream?


I have a small function which converts double to std::string:

std::string convertDoubleToString( double value ) {
    std::ostringstream ostr;
    ostr << value;
    return ostr.str();
}

I don't want to use the scientific notation here. How can I do it in this case? I can use std::fixed or cout.setprecision but it works for std::cout only but how can I use it for my case?


Solution

  • Use std::fixed manipulator like this:

     ostr << std::fixed << value;