gen*_*gen 0 c++ floating-point truncate rounding fractions
C++
我想cout float f = 2.3333,但只有两位小数.我怎么做?我记得这样的事情,但它不起作用:
cout << f:2 << endl;
Run Code Online (Sandbox Code Playgroud)
    使用流操纵器fixed和setprecision:
#include <iomanip>
float f = 2.3333;
std::cout << std::setprecision(2) << std::fixed << f;
Run Code Online (Sandbox Code Playgroud)