以C++输出小数点两位数为例 setprecision(n)使用方法总结 首先要记住写头文件 #include <iomanip> //不要忘了头文件 以下是控制小数位数的三种写法 //the first cout<<setiosflags(ios::fixed)<<setprecision(2); //the second cout.setf(ios::fixed); cout<<setprecision(2); //the third cout<<fixed<<setprecision(2); 想要保留几位小数setprecision(n)中n就写成几一定要记得写头文件##