To set fixed 2 digits after the decimal point, use them first:
cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2);
Then print the double values.
That's an example:
#include <iostream> using std::cout; using std::ios; using std::endl; int main(int argc, char *argv[]) { cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); double d = 10.90; cout << d << endl; return 0; }
Hamid Rohani Nov 28 '16 at 10:39 2016-11-28 10:39
source share