printf %g 是啥?
来源:互联网 发布:nodejs引入js 编辑:程序博客网 时间:2024/04/30 08:04
printf 格式化输出 有很多种可以选择的格式化方式。通常我们最多使用的就是 %s %d %f %c 等。其实还有一些别的选择。配合数字选项,可以灵活实现一些特定的东西。
MSDN中的说法:
c int or wint_t When used with printf functions, specifies a single-byte character; when used with wprintf
functions, specifies a wide character.
C int or wint_t When used with printf functions, specifies a wide character; when used with wprintf functions,
specifies a single-byte character.
d int Signed decimal integer.
i int Signed decimal integer.
o int Unsigned octal integer.
u int Unsigned decimal integer.
x int Unsigned hexadecimal integer, using “abcdef.”
X int Unsigned hexadecimal integer, using “ABCDEF.”
e double Signed value having the form [ – ]d.dddd e [sign]ddd where d is a single decimal digit, dddd is one or
more decimal digits, ddd is exactly three decimal digits, and sign is + or –.
E double Identical to the e format except that E rather than e introduces the exponent.
f double Signed value having the form [ – ]dddd.dddd, where dddd is one or more decimal digits. The number of
digits before the decimal point depends on the magnitude of the number, and the number of digits after the decimal
point depends on the requested precision.
g double Signed value printed in f or e format, whichever is more compact for the given value and precision. The e
format is used only when the exponent of the value is less than –4 or greater than or equal to the precision
argument. Trailing zeros are truncated, and the decimal point appears only if one or more digits follow it.
G double Identical to the g format, except that E, rather than e, introduces the exponent (where appropriate).
n Pointer to integer Number of characters successfully written so far to the stream or buffer; this value is stored
in the integer whose address is given as the argument.
p Pointer to void Prints the address pointed to by the argument in the form xxxx:yyyy where xxxx is the segment and
yyyy is the offset, and the digits x and y are uppercase hexadecimal digits.
s String When used with printf functions, specifies a single-byte–character string; when used with wprintf
functions, specifies a wide-character string. Characters are printed up to the first null character or until the
precision value is reached.
S String When used with printf functions, specifies a wide-character string; when used with wprintf functions,
specifies a single-byte–character string. Characters are printed up to the first null character or until the
precision value is reached.
总结:
%S 用于指定宽字符串。wprintf("%S",(wchar*)str);
%C 也是用于宽字符。 wprintf("%C",(wchar)wc);
%d或%i 有符号的10进制整形 printf("%i",nval);
%u 无符号的10进制整形 printf("%u",unval);
%o 无符号8进制整形 printf("%o",oval);
%x或%X 十六进制小写或大写格式 printf("%2X",hexval);
%f 浮点方式标示 printf("%.2f",fval); 保留小数点后的个数
%e 科学计数法表示 printf("%e",fval);
%E 什么含义?
%g 根据具体的数值选择 %e 或 %f printf("%.2g",0.0123); ====> 0.012 效果相当于除去0后的有效位数
%G 根据具体数值选择 %E 或 %f
%p 指针形式 printf("%p",&fval); 等效于 printf("%08X",&fval);
%n 还不知道怎么用
其他请补充……
- printf %g 是啥?
- printf %g 是啥?
- printf %g 的精度问题
- printf是在libc库中么?
- Printf 里%f,%g的若干使用
- poj2823 单调队列 ------scanf/printf/G++/C++
- G是产生器
- VoLTE到底是啥?4G网络常见名词解释
- 看来 printf 是个取消点
- oh,原来是printf的错
- cout和printf是有区别的
- printf 参数传递顺序是从右至左
- Printf是从右向左压入栈
- 5G是一场革命
- printf
- printf
- printf
- printf()
- Android系统Gps分析
- 杭电acm 数学类型的题
- CSS3 transform的skew属性值详解
- linux提供了select、poll、epoll接口来实现IO复用,三者的原型如下所示,本文从参数、实现、性能等方面对三者进行对比。
- 配置全局结果
- printf %g 是啥?
- 在Windows下使用Emacs 20
- interceptor拦截器模板
- 视差滚动原理及实现
- 如何在拦截器中获取request对象
- 模型导出U3D格式开发库
- 作业4
- java LDAP分页查询 解决1000条限制
- Struts标签if判断两个字符串是否相等