Check out example codes for "setprecision in c++". It will help you in understanding the concepts better.

Code Example 1

#include<iomanip>
#include <iostream>
using namespace std;

int main()
{
   int num = 45;
  cout << "it is: " << fixed << setprecision(2) << num << " the end"<< endl;
  
  return 0;
}

Code Example 2

// setprecision example
#include <iostream>     // std::cout, std::fixed
#include <iomanip>      // std::setprecision

int main () {
  double f =3.14159;
  std::cout << std::setprecision(5) << f << '\n';
  std::cout << std::setprecision(9) << f << '\n';
  std::cout << std::fixed;
  std::cout << std::setprecision(5) << f << '\n';
  std::cout << std::setprecision(9) << f << '\n';
  return 0;
}

Code Example 3

float x;
cout<<fixed<<showpoint;
cout<<setprecision(2) << x;

Code Example 4

int x = 109887;
cout << fixed << setprecision(3) << x;

Code Example 5

printf("%0.4f", num);

Learn ReactJs, React Native from akashmittal.com