% 2D in C Language

Source: Internet
Author: User
Let's take a look at the following instructions:

Modifier format description meaning

Int A = 1; int B = 1234; double C = 1.2345678; printf ("% 2D \ n", a); printf ("% + 2d \ n", ); printf ("% 4D \ n", a); printf ("% 2D \ n", B); printf ("% + 2d \ n", B ); printf ("% 4D \ n", B); printf ("% 2.2f \ n", C );
M % MD outputs the integer value in width m. If the value is less than m, fill in spaces on the left.
0 m % 0md outputs the integer number with the width m. If the value is less than m, the value is left zero.
M, N % m. NF output real decimal places in width m, and decimal places are n digits

Double I = 12.3,
Printf ("% 2f", I, );
Output: 12.300000
Printf ("% 2.1f", I, );
Output: 12.3

When the specified field width is less than the actual width of the data, the number of integers is output according to the actual field width of the number, and the number of decimal places is rounded to the floating point number. Int I = 1; printf ("% 04d", I );
Output: 0001% 04d, 4 digits in decimal format. If it is not enough, add 0 in front.

 

Related Article

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.