// setprecision example
#include <iostream>
#include <iomanip>
using namespace std;
int main () {
double f =3.14159;
cout << setprecision (5) << f << endl; //3.1416
cout << setprecision (9) << f << endl; //3.14159
cout << fixed;
cout << setprecision (5) << f << endl; //3.14159
cout << setprecision (9) << f << endl; //3.141590000
return 0;
}
http://www.cplusplus.com/reference/iostream/manipulators/setprecision/