以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就写成几
  • 一定要记得写头文件##
posted on 2020-05-23 22:50  weiyuexin  阅读(1504)  评论(0)    收藏  举报