fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <float.h>
  4.  
  5. int main(void) {
  6. float f = 1.10;
  7. float truncado = (f - trunc(f)) * 10;
  8. printf("Truncado: %f\n", truncado);
  9. float mod = fmodf(truncado, 1.0f);
  10. printf("Mod: %.*f\n", DBL_DIG-1, mod);
  11. if (mod != 0){
  12. printf("%.2f", f);
  13. }
  14. else{
  15. printf("%.1f", f);
  16. }
  17. return 0;
  18. }
  19.  
Success #stdin #stdout 0s 9432KB
stdin
Standard input is empty
stdout
Truncado: 1.000000
Mod: 0.00000023841858
1.10