Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Regarding the question of C language, the third decimal place should be rounded off.
Regarding the question of C language, the third decimal place should be rounded off.
C language has no direct function of rounding the third decimal place, but it can be realized indirectly.

The specific ideas are as follows:

Multiply this number by 100 to make the third place after the decimal point the first place;

The rounding of C language is a community decimal, not a rounding. At this time, adding 0.5 to the number can achieve the rounding effect without calling any rounding function.

The implementation code and comments are as follows:

Invalid? Master ()

{

Double? num = 3. 14 159; ? //Here we use the value distance of pi.

num=? (int)(num * 100+0.5); ? //Multiply by 100+0.5 and round it off.

printf("%.3lf ",num); ? //output results

}