Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

setprecision in c++

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);
}
 
PREVIOUS NEXT
Tagged: #setprecision
ADD COMMENT
Topic
Name
6+8 =