c++ - using stringstream to print a rounded floating point number - Stack Overflow

PHOTO EMBED

Mon Jun 27 2022 16:30:00 GMT+0000 (Coordinated Universal Time)

Saved by @ssstevenson #cpp

#include <sstream>
#include <iostream>
#include <iomanip>

int main()
{
  double d = 12.3456789;
  std::stringstream ss;

  ss << std::fixed << std::setprecision( 4 ) << d;

  std::cout << ss.str() << std::endl;
}
content_copyCOPY

https://stackoverflow.com/questions/7734609/using-stringstream-to-print-a-rounded-floating-point-number