Today, I want to create a demo to obtain test data. I encountered a particularly basic language problem. Mark it down. If the left and right values of the binary operator numbers are integer, the resulting values are also integer, for example, a small demo:
Int A = 64 ;
Int B = 65 ;
Float F = ( Float ) (B / A );
Float F2 = ( Float ) ( / B );
Printf ( " % F " , F, F2 ); // Result: 1.000000 0.000000
/* **************************************** *********** */
Float C = 65.0f ;
Float F3 = A / C;
Float F4 = C / A;
Printf ( " % F " , F3, F4 ); // Result: 0.984615 1.015625
I can deeply understand what I mentioned above. In addition, when printf and sprintf are used for string printing or conversion, % F generally retains the six digits after the decimal point by default. % E indicates the double floating point type, which is generally 14 digits after the decimal point, to control the number of digits after the decimal point, you can use "%. 4f "in this way, the four digits after the decimal point are retained.
Note that when using sprintf for data conversion, other parameters except the first two parameters are not of the type security, therefore, in some cases, the type must be forcibly converted, for example:
Int A = 100 ;
Printf ( " % F " , ); // Result: 0.000000
/* ************************************** */
Printf ("% F",(Float) );//Result: 100.000000