fork download
  1. #include <stdio.h>
  2.  
  3. int main(void)
  4. {
  5. int xi;
  6. float xf = 6.9;
  7.  
  8. printf("float: %.20f\n", xf);
  9.  
  10. xi = (int)xf;
  11. printf("truncated: %d\n", xi);
  12.  
  13. xi = (int)(xf+0.5);
  14. printf("rounded: %d\n", xi);
  15.  
  16. }
Success #stdin #stdout 0s 2168KB
stdin
Standard input is empty
stdout
float: 6.90000009536743164062
truncated: 6
rounded: 7