Controlling precision of floating-point values
#include <iostream> #include <iomanip> using std::cout; using std::cin; using std::endl; using std::ios; using std::setiosflags; using std::setprecision; #include <cmath> int main() { double root2 = sqrt( 2.0 ); int places; cout << setiosflags( ios::fixed) << endl; for ( places = 0; places <= 9; places++ ) { cout.precision( places ); cout << root2 << '\n'; } for ( places = 0; places <= 9; places++ ) cout << setprecision( places ) << root2 << '\n'; return 0; }