Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - When will rounding be used in data processing in C language? thank you
When will rounding be used in data processing in C language? thank you
It seems that there is no such thing as rounding, only to give up everything, that is, when floating-point type is converted into integer type, the decimal places are directly removed and the integer bits are kept.

For example:

b=a+c+0.5

Principle: If a+c = 10. 18860.8886868666 17

So a+c+0.5= 10.99999999, is it int or b= 10?

And:

Integer divided, 5/3 =1;

Remainder 5% 3 = 2;

When rounding is needed, you should use double precision or floating-point number to calculate and then judge whether it is true or not, and give a simple:

Floating a;

int b;

If (a-0.5 >; = a/ 1)b = a/ 1+ 1;

else b = a/ 1;