cout输出小数位数
#include <iostream> #include <iomanip> /* 需要头文件:"iomanip" iomanip表示: io manipulator */ using namespace std; int main() { float a = 0.123000789; cout.setf(ios::fixed);//打开自动补位 cout << "a=" <<fixed<< setprecision(5) << a <<endl; cout.unsetf(ios::fixed);//关闭自动补位 cout << "a=" << setprecision(5) << a <<endl; }
浙公网安备 33010602011771号