是什么f由于C%G和%之间的区别? [英] What is the difference between %g and %f in C?

查看:203
本文介绍了是什么f由于C%G和%之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正要通过K&放C编程语言; R。在这里,在一份声明中打印它是写一个双变量

I was going through The C programming Language by K&R. Here in a statement to print a double variable it is written

printf("\t%g\n", sum += atof(line));

其中总和被声明为双。任何人都可以请帮我时,双或浮动的情况和最新%G和%F之间的差异的情况下,使用%G。

where sum is declared as double. Can anybody please help me out when to use %g in case of double or in case of float and whats the difference between %g and %f.

推荐答案

请参阅任何的参考手册,如手册页

See any reference manual, such as the man page:

F,F

双论点是圆形,并在风格转换为十进制符号[ - ] ddd.ddd,其中的小数点字符后的数字位数等于precision规范。如果precision丢失,它被当作6;如果precision是明确为零,没有出现小数点字符。如果出现小数点,至少有一个数字之前出现。
  (该SUSv2不知道F和说,字符串重新presentations为无穷大和NaN可提供的C99标准规定[ - ] INF'或者'[ - ]无限为无穷大,和一个字符串以'南'楠,在F转换,和的情况下,'[ - ] INF'或者 - 在F转换的情况下,'[] INFINITY'或'NAN *')

The double argument is rounded and converted to decimal notation in the style [-]ddd.ddd, where the number of digits after the decimal-point character is equal to the precision specification. If the precision is missing, it is taken as 6; if the precision is explicitly zero, no decimal-point character appears. If a decimal point appears, at least one digit appears before it. (The SUSv2 does not know about F and says that character string representations for infinity and NaN may be made available. The C99 standard specifies '[-]inf' or '[-]infinity' for infinity, and a string starting with 'nan' for NaN, in the case of f conversion, and '[-]INF' or '[-]INFINITY' or 'NAN*' in the case of F conversion.)

g,G之前

双参数转换风格F或E(或F或E为G转换)。的precision指定显著位数。如果precision丢失,6位给出;如果precision是零,它被视为1.款e的使用,如果从它的转换的指数小于-4或大于或等于precision。尾随零将从结果的小数部分删除;小数点出现仅当随后的至少一个数字。

The double argument is converted in style f or e (or F or E for G conversions). The precision specifies the number of significant digits. If the precision is missing, 6 digits are given; if the precision is zero, it is treated as 1. Style e is used if the exponent from its conversion is less than -4 or greater than or equal to the precision. Trailing zeros are removed from the fractional part of the result; a decimal point appears only if it is followed by at least one digit.

这篇关于是什么f由于C%G和%之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆