-1

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?

JavaRunner
  • 2,455
  • 5
  • 38
  • 52

1 Answers1

1

Use std::fixed manipulator like this:

 ostr << std::fixed << value;
ikleschenkov
  • 972
  • 5
  • 11
  • Didn't know it works for all streams as well. Worked this way: *ostr << std::fixed << std::setprecision( 10 ) << value;* - without setprecision it returns too "short" value :) – JavaRunner Jul 26 '17 at 11:50