Review of printf format requirements

Source: Internet
Author: User
Printf

1. Conversion specifiers
% A (% A) floating point number, hexadecimal number, and P-(p-) Notation (c99)
% C characters
% D signed decimal integer
% F floating point number (including float and doulbe)
% E (% E) floating point number index output [E-(e-) Note]
% G (% G) floating point number does not show meaningless zero "0"
% I signed decimal INTEGER (same as % d)
% U unsigned decimal integer
% O octal integer e.g. 0123
% X (% x) hexadecimal integer 0f (0f) e.g. 0x1234
% P pointer
% S string
% "%"

2. Flag
Left alignment: "-" e.g. "%-20 s"
Right alignment: "+" e.g. "% + 20 s"
Space: If the symbol is positive, space is displayed. If the symbol is negative, "-" e.g. "% 6.2f" is displayed"
#: PairClass C, S, D, and u have no effect. For Class O, prefix o is added for output; For Class X, prefix 0x is added for output;
The decimal point is given for Class E, G, and F when the result has decimal places.

3. Format String (Format)
[Flag] [minimum output width] [. Precision] [length] Type
"%-MD": Left alignment. If the M ratio is small, it is output as needed.
"% M. Ns": output M-bit. Take the string (from left) N-bit, left fill space, when n> m or M is omitted, M = N
E.g. "% 7.2 s" input China
Output "ch"
"% M. NF": Output floating point number. M indicates the width, and N indicates the right digit of the decimal point.
E.g. "% 3.1f" input 3852.99
3853.0 output
Length: H short integer, l long integer

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.