fork download
  1. #include <iomanip>
  2. #include <iostream>
  3. #include <math.h>
  4. #include <tgmath.h>
  5. using namespace std;
  6. double round_with_precision(double d, const int &prec)
  7. {
  8. d *= pow(10, prec);
  9. return std::round(d) / pow(10, prec);
  10. }
  11. int main(){
  12. const int prec = 2;
  13. cout << round_with_precision(1.7/20, prec) << endl;
  14. cout << round_with_precision(1.1/20, prec) << endl;
  15. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
0.09
0.06