fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. int main() {
  6.  
  7. double value = 0.87499999;
  8. printf( "print value (0.87499999) : %.6e\n", value );
  9.  
  10. printf( "quotient in wrong way : %d\n", (int)(value*1000) / 5 );
  11.  
  12. // replacing : integral = (int)((value)*1000)
  13. int integral = (int)nearbyint( value*1000 );
  14. printf( "quotient in right way : %d\n", integral / 5 );
  15.  
  16. return EXIT_SUCCESS;
  17. }
Success #stdin #stdout 0.01s 1720KB
stdin
Standard input is empty
stdout
print value (0.87499999) : 8.750000e-01
quotient in wrong way : 174
quotient in right way : 175