fork(3) download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. double round(double value, int digits)
  5. {
  6. double factor = pow(10.0, 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. int main(void) {
  13.  
  14. printf("%.52g", round(-123.23344553, 6));
  15. return 0;
  16. }
Success #stdin #stdout 0.01s 1720KB
stdin
Standard input is empty
stdout
-123.2334455284139522746045258827507495880126953125