[Original] C language Operators

Source: Internet
Author: User

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.