fork(1) download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. void foo( const double d )
  7. {
  8. const double rounded_2_decimals = std::round(d*100.0) / 100.0;
  9. std::cout << "d=" << std::setprecision(9) << d << std::endl;
  10. std::cout << "r=" << std::setprecision(9) << rounded_2_decimals << std::endl;
  11. }
  12.  
  13. int main() {
  14. // your code goes here
  15. double d = 3.1249999;
  16.  
  17. foo(d);
  18.  
  19. return 0;
  20. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
d=3.1249999
r=3.12