fork(4) download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. double round(double value, int digits)
  5. {
  6. double factor = pow(10.0, ceil(log10(fabs(value))) + digits);
  7. value *= factor ;
  8. value = value >= 0.0 ? floor(value + 0.5) : ceil(value - 0.5);
  9. return value / factor;
  10. }
  11.  
  12.  
  13. int main(void) {
  14.  
  15. printf("%.52g", round(-123.23344553, 6));
  16. return 0;
  17. }
Success #stdin #stdout 0.01s 1720KB
stdin
Standard input is empty
stdout
-123.2334455299999973476587911136448383331298828125