I know this is a very old post but I was looking for a solution to the same problem. However, I did not want to create a special function for it so I came up with the following:
#include
#include
...
...
...
double val = 3.14159;
stringstream tmp;
tmp << setprecision(3) << fixed << val;
double new_val = stod(tmp.str()); // new_val = 3.143
tmp.str(string()); // clear tmp for future use
Not sure if this is the best way to do it but it worked for me!