how to set decimal precision in c++ code example
Example 1: setprecision in c++
#include<iomanip>
#include <iostream>
using namespace std;
int main()
{
int num = 45;
cout << "it is: " << fixed << setprecision(2) << num << " the end"<< endl;
return 0;
}
Example 2: how to print 5 precision float in c++
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
// This code helps you to print a number with desired decimal
double Number=10.3454;
printf("%.3lf",Number);
return 0;
}