C语言中%5.2f中的5和.2都分别代表什么意思?求详细解释!

 我来答
匿名用户
2018-03-02
展开全部

%[flags] [width] [.precision] [{h | l | ll | w | I | I32 | I64}] type

%                5      .2                          f

最小宽度为5,精度到小数点2位的浮点数格式输出。

详情请看下面:

Format Specification Syntax: printf and wprintf Functions

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Format Specification Syntax: printf and wprintf Functions.

Describes the syntax for format string arguments to printf, wprintf, and related functions. More secure versions of these functions are available; for more information, see Security Features in the CRT. For information about the individual functions, see the documentation for those specific functions. For a listing of these functions, see Stream I/O.

A format specification, which consists of optional and required fields, has the following form:

%[flags] [width] [.precision] [{h | l | ll | w | I | I32 | I64}] type

Each field of the format specification is a character or a number that signifies a particular format option or conversion specifier. The required type character specifies the kind of conversion to be applied to an argument. The optional flags, width, and precision fields control additional format aspects. A basic format specification contains only the percent sign and a type character—for example, %s, which specifies a string conversion. In the secure versions of the functions, if a percent sign is followed by a character that has no meaning as a format field, the invalid parameter handler is invoked. For more information, see Parameter Validation. In the non-secure versions, the character is copied to the output unchanged. To print a percent-sign character, use %%.

The fields of the format specification control the following aspects of argument conversion and formatting:

type
Required conversion specifier character that determines whether the associated argument is interpreted as a character, a string, an integer, or a floating-point number. For more information, see printf Type Field Characters.

flags
Optional character or characters that control output justification and output of signs, blanks, leading zeros, decimal points, and octal and hexadecimal prefixes. For more information, see Flag Directives. More than one flag can appear in a format specification, and flags can appear in any order.

width
Optional decimal number that specifies the minimum number of characters that are output. For more information, see printf Width Specification.

precision
Optional decimal number that specifies the maximum number of characters that are printed for strings, the number of significant digits or the number of digits after the decimal-point character for floating-point values, or the minimum number of digits that are printed for integer values. For more information, see "How Precision Values Affect Type" in Precision Specification.

h | l | ll | w | I | I32 | I64
Optional prefixes to type that specify the size of the corresponding argument. For more information, see"Size Prefixes" in Size Specification.

chinaboyzyq
2016-01-12 · TA获得超过1.3万个赞
知道大有可为答主
回答量:1.3万
采纳率:89%
帮助的人:3261万
展开全部
整数5位,小数2位,整数不够5位时以空格点位。
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
更无止境时I
推荐于2018-03-02 · TA获得超过121个赞
知道答主
回答量:109
采纳率:0%
帮助的人:36万
展开全部

本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式