Set precision for float number output : float output « Data Types « C++ Tutorial






#include <iostream>
using namespace std; 
int main(void)
{
   int i;
   float value = 1.2345;

   for (i = 0; i < 4; i++){
      cout.precision(i);
      cout << value << endl;
   }
}








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