#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
long double my_round(long double value, unsigned decimal_places)
{
long double mult = std::pow(10.0L, decimal_places);
return std::round(value * mult) / mult;
}
int main()
{
long double Fred = 9.56756785685685682595L;
auto max_prec = std::numeric_limits<long double>::digits10;
for (unsigned i = 0; i < max_prec; ++i)
{
std::cout << "decimal places: " << i << '\n';
std::cout << std::setprecision(max_prec) << Fred << '\n';
std::cout << std::setprecision(i+2) << my_round(Fred, i) << "\n\n";
}
}
I2luY2x1ZGUgPGNtYXRoPgojaW5jbHVkZSA8aW9tYW5pcD4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bGltaXRzPgoKbG9uZyBkb3VibGUgbXlfcm91bmQobG9uZyBkb3VibGUgdmFsdWUsIHVuc2lnbmVkIGRlY2ltYWxfcGxhY2VzKQp7CiAgICBsb25nIGRvdWJsZSBtdWx0ID0gc3RkOjpwb3coMTAuMEwsIGRlY2ltYWxfcGxhY2VzKTsKICAgIHJldHVybiBzdGQ6OnJvdW5kKHZhbHVlICogbXVsdCkgLyBtdWx0Owp9CgppbnQgbWFpbigpCnsKICAgIGxvbmcgZG91YmxlIEZyZWQgPSA5LjU2NzU2Nzg1Njg1Njg1NjgyNTk1TDsKICAgIGF1dG8gbWF4X3ByZWMgPSBzdGQ6Om51bWVyaWNfbGltaXRzPGxvbmcgZG91YmxlPjo6ZGlnaXRzMTA7CgogICAgZm9yICh1bnNpZ25lZCBpID0gMDsgaSA8IG1heF9wcmVjOyArK2kpCiAgICB7CiAJCXN0ZDo6Y291dCA8PCAiZGVjaW1hbCBwbGFjZXM6ICIgPDwgaSA8PCAnXG4nOwogCQlzdGQ6OmNvdXQgPDwgc3RkOjpzZXRwcmVjaXNpb24obWF4X3ByZWMpIDw8IEZyZWQgPDwgJ1xuJzsKICAgICAgICBzdGQ6OmNvdXQgPDwgc3RkOjpzZXRwcmVjaXNpb24oaSsyKSA8PCBteV9yb3VuZChGcmVkLCBpKSA8PCAiXG5cbiI7CiAgICB9Cn0=