C++ double 小数精度控制

第一种方法:cout<<fixed<<setprecision(20)<<mydouble<<endl;

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
	double aDouble = 5.141592694827862736487362746374637434343434;
	cout<<fixed<<setprecision(20)<<aDouble<<endl;
	return 0;
}


另外一种方法:cout.precision(dbl::digits);

#include <iostream>
using namespace std;

int main()
{
	typedef numeric_limits< double > dbl;
	double pi = 3.141592694827862736487362746374637434343434;
	cout.precision(dbl::digits10);
	cout << "Pi: " << fixed << pi << endl;

	return 0;
}




posted @ 2017-06-15 14:13  lytwajue  阅读(4800)  评论(0编辑  收藏  举报