stringstram does not allow precision on parsing, but you may set the double precision after parsing.
E.g.
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cmath>
using namespace std; //do not use that in real project.
int main()
{
// Initial declarations
stringstream ss("13.321646");
double x = 0.0;
// Parse the double
ss >> x;
// Set the double precision to 2decimals
double roundedX = round(x*100)/100;
// output solution
cout << x << endl;
cout << setprecision(5) << x << endl;
cout << roundedX << endl;
return 0;
}
Obvious note: That allow to reduce precision, not to improve it.
3.1415926536, I don't expect to get3.14159. If there's some reason why input should be limited to five digits after the decimal (and fixed format? or is1.5e-100acceptable?), then this test must be done on the text input, and the user must get an error message if he enters something invalid.