Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - May I ask why the output result of the float variable is 1 instead of 1.00000?
May I ask why the output result of the float variable is 1 instead of 1.00000?
Because the operation/itself is truncated and rounded, although 4 divided by 3 has a decimal part, the expression 4/3 actually takes the integer part of 4 divided by 3, namely 1, so temp is actually a complete integer 1, and the output is naturally 1.

For example, if you define a variable float a = 1, the output will naturally be 1 instead of 1.0000(n) with decimal 0. .

But if you want it to be output in decimal form (in fact, to improve accuracy), you can set it. .