Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to convert int into float in C language? Why is there rounding?
How to convert int into float in C language? Why is there rounding?
Usually, floating point has 24 bits to represent significant digits. For integers, after 2 24, many numbers cannot be accurately represented, such as 2 24+1.

If int 2 24+ 1 is converted to floating point number, it can only be converted to the nearest 2 24.

Specifically, by running the following code, you will know:

# Contains? & ltstdio.h & gt

# Contains? & ltmath.h & gt

int? Major (invalid)

{

int? Answer? =? pow(2,24)? +? 1;

Floating? b;

b? =? a;

printf("a? =? %d\n ",a);

printf("b? =? %lf\n ",b);

}