R
rupert
i've got the following code:
and the value of precision is 6 when there's only 3 sigificant figures.
I would have exptected precision() to return an integer of value 3, any
ideas?
Code:
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
using namespace std;
int main(double argc, char* argv[ ]) {
double r = 0.01;
double s = 1.04;
double t = 2.23;
double u = 2.23;
vector<double> v;
v.push_back(r);
v.push_back(s);
v.push_back(t);
v.push_back(u);
streamsize prec = cout.precision();
cout << "precision of doubles:..." << prec << endl;
double sum = v[0]+v[1]+v[2]+v[3];
cout << "actual number:..." << sum << endl;
cout <<"presision set at 2:..."<< setprecision(2) << sum << endl
<< "precision set at "<< prec << ":..." << setprecision(prec)
<< " "<< sum << endl;
return EXIT_SUCCESS;
}
I would have exptected precision() to return an integer of value 3, any
ideas?