Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - What's wrong if I output an integer with% f?
What's wrong if I output an integer with% f?
1.8/5 defaults to integer operation, and the output can be normal with %d, that is, printf("%d ",8/5); In normal 2.c language, the result of integer data operation is output with %f, and the result is always 03. Integer data is output with %f, and the system will not perform forced type conversion. If you want to use forced type conversion, it must be as follows: printf("%f ",(float)8/5); 8/5); Or printf("%f ",(double)8/5); 8/5); 4. Automatic type conversion: printf("%f ",8.0/5); Or printf("%f ",8/5.0); At this point, the system will automatically switch to floating-point operation, and the output result is 1.600000.