Set precision for float number : float output « Data Type « C++






Set precision for float number

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

   for (i = 0; i < 4; i++)
     cout << setprecision(i) << value << '\n';
}
  
    
  








Related examples in the same category

1.Output float number with fixed flag
2.Output float type number with scientific format
3.Change cout width and precision for string and float number output
4.Output float in default floating-point format
5.Floating-point values in system default, scientific, and fixed formats.
6.Controlling precision of floating-point values