C++ double类型转string类型后,怎么实现小数点后只显示一个数字
#include <iostream>
#include <sstream>
#include <iomanip>
template
<
class
T>
std::string fmt(T in,
int
width = 0,
int
prec = 0) {
std::ostringstream s;
s << std::setw(width) << std::setprecision(prec) << in;
return
s.str();
}
int
main(){
std::string s = fmt(66.0 / 30.0, 2, 2);
std::cout << s <<
"\n"
;
}