Normal (default) mode; only show 5 digits, including both sides of decimal point : cout float « Development « C++ Tutorial






#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

int main( ) {

   ios_base::fmtflags flags = cout.flags( );

   double pi = 3.14285714;

   cout << "pi = " << setprecision(5) << pi << '\n';

   cout.flags(flags);
}
pi = 3.1429








5.6.cout float
5.6.1.Displaying floating-point values in system default, scientific and fixed formats
5.6.2.ios::right|ios::scientific|ios::showpoint
5.6.3.Displaying numbers in scientific notation
5.6.4.Normal (default) mode; only show 5 digits, including both sides of decimal point
5.6.5.Controlling precision of floating-point values