Controlling the printing of trailing zeros and decimal points for floating-point values. : float output « Data Types « C++ Tutorial






#include <iostream>
#include <iomanip>
#include <cmath>

using std::cout;
using std::endl;
using std::ios;

int main()
{      
   cout << "Before setting the ios::showpoint flag\n"
        << "9.9900 prints as: " << 9.9900 
        << "\n9.9000 prints as: " << 9.9000
        << "\n9.0000 prints as: " << 9.0000
        << "\n\nAfter setting the ios::showpoint flag\n";
   cout.setf( ios::showpoint );
   cout << "9.9900 prints as: " << 9.9900 
        << "\n9.9000 prints as: " << 9.9000
        << "\n9.0000 prints as: " << 9.0000 << endl;
   return 0;
}








2.11.float output
2.11.1.Set precision for float number output
2.11.2.Set and clear the showpoint flag
2.11.3.Controlling the printing of trailing zeros and decimal points for floating-point values.
2.11.4.Read and output float
2.11.5.pad the field width with spaces and set the internal and showpos flags