#include<iomanip>
#include <iostream>
using namespace std;
int main()
{
int num = 45;
cout << "it is: " << fixed << setprecision(2) << num << " the end"<< endl;
return 0;
}
double num = 3.14;
cout << fixed;
// Using setprecision()
cout << "Setting the precision using"
<< " setprecision to 5:
"
<< setprecision(5);
cout << num << endl;
/*
Using setprecision you don't get to set the precision after the decimal point.
So for that reason you can go with God Language C using scanf.
Implementation for the same below
*/
//Use this for getting upto 2 decimal value after the decimal point
#include<cstdio>
int main() {
double total;
cin>>total;
printf("%.2f
", total);
}
cout << "Setting the precision using"
<< " setprecision to 9 :
"
<< setprecision(9);
// this is the output
Setting the precision using setprecision to 9:
3.140000000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream> //standard input-output stream
#include <iomanip> //input_output_manipulation
using namespace std;
int main(int argc, char const *argv[])
{
float R;
cin >> R;
float A = 3.14159 * R * R;
cout << "A=" << fixed << setprecision(4) << A << endl;
return 0;
}
// setprecision counts whole number >>> EX:: 34.1234 is equal setprecision(6)
// When the fixed keyword is used, the argument in the setprecision()
// function specifies the number of decimal places to be printed in the output.
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int i = 18;
cout<<setw(10)i;
}