第一种方法: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; }
C++ double 小数精度控制,布布扣,bubuko.com
原文地址:http://blog.csdn.net/exlsunshine/article/details/37501723