当前位置: 代码迷 >> C语言 >> double输出格式是%lf吗?
  详细解决方案

double输出格式是%lf吗?

热度:485   发布时间:2007-08-29 08:02:59.0
double输出格式是%lf吗?
double输出格式是%lf吗?
搜索更多相关的解决方案: double  格式  输出  

----------------解决方案--------------------------------------------------------

%f


----------------解决方案--------------------------------------------------------
float也是%f,这两种就没区别了~~
----------------解决方案--------------------------------------------------------
lf
----------------解决方案--------------------------------------------------------

到底应该是怎样呢?


----------------解决方案--------------------------------------------------------
lf,用f会丢失掉精度~~~~~
----------------解决方案--------------------------------------------------------
%f or %lf 都可以



by 雨中飞燕 QQ:78803110 QQ讨论群:5305909

请大家不要用TC来学习C语言
C/C++算法习题(OnlineJudge):[url]http://yzfy.org/[/url]
----------------解决方案--------------------------------------------------------
回复:(雨中飞燕)%f or %lf 都可以[img]http://bbs....


No, simply f, Neither lf nor Lf:

For printf():

l: The argument is interpreted as a long int or unsigned long int for integer specifiers (i, d, o, u, x and X), and as a wide character or wide character string for specifiers c and s.
L: The argument is interpreted as a long double (only applies to floating point specifiers: e, E, f, g and G).


For scanf():

l : long int (for d, i and n), or unsigned long int (for o, u and x), or double (for e, f and g)
L : long double (for e, f and g)


----------------解决方案--------------------------------------------------------
版主,我看得不很明白,但是在下面这个程序中:
#include<stdio.h>
main()
{
double t;
scanf("%f",&t);
printf("%f",t);
}
//输入1,结果 -92559604281615349000000000000000000000000000000000000000000000.000000
改为:scanf("%lf",&t);就OK了.为什么?



----------------解决方案--------------------------------------------------------
因为你定义的是double类型的
----------------解决方案--------------------------------------------------------
  相关解决方案