Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Why do floating-point numbers have to be converted into integers and only take the integer part?
Why do floating-point numbers have to be converted into integers and only take the integer part?
Floating point numbers can store decimal parts, and integers can only store integers, float a = 0.123; int b = 0;

b =(int)a; //This integer variable can only take the integer part of a. If you want to put the decimal of a floating-point variable,

Some parts are also omitted, such as a = 0.123; Think b= 123, that's it; b =(int)(a * 1000);

Then when calculating b, remember that b needs to be divided by 1000 to be the actual value.