Hey all, I'm trying to write a function that computes pi to the nth digit. I have it almost working but it fails for some cases.
#include <cmath>
#include <algorithm>
double myPi(int n) {
std::string ten = "1";
for(int i = 0; i < n; i++){
ten += "0";
}
std::string tmp_ten = (ten + "0");
float prior = ((float)(int)(M_PI*std::stoi(tmp_ten))/std::stoi(tmp_ten));
std::string prior_str = std::to_string(prior);
prior_str.erase(remove(prior_str.begin(), prior_str.end(), '0'), prior_str.end());
if((int(prior_str.back())-48) >= 5){