Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - What is the rounding of C language?
What is the rounding of C language?
# incloud & ltstdio & gt

int main(void)

{

Floating a;

scanf("%f ",& ampa);

a =(int)(a * 1000+0.5)/ 1000.0;

printf ("%0.3f ",a);

Returns 0;

}

Extended data:

Other methods to achieve rounding:

int myround(double indata,int precision,double * outdata)

{?

long pre = 1,I;

for(I = 0; I< accuracy; i++)pre = pre * 10;

if(cy_FloatCompare(indata,0.00)>0)

* out data =(int)((in data * pre)+0.5)/ 100.00;

Or what?

* out data =(int)((in data * pre)-0.5)/ 100.00;

Returns 0;

}?

// cy_FloatCompare is a function that compares floating-point numbers with 0, assuming it exists. The return value is the same as strcmp.