%f和%lf用什么不同
?char c = 'a';
? ? int n = c ; ? ?//將c賦值給n
? ? float f = c; ? ? ?//將c賦值給f
? ? double d = ?c; ? ?//將c賦值給d
? ? printf("%d\n",n);
? ? printf("%f\n",f);
? ? printf("%lf\n",d);
? ??
?char c = 'a';
? ? int n = c ; ? ?//將c賦值給n
? ? float f = c; ? ? ?//將c賦值給f
? ? double d = ?c; ? ?//將c賦值給d
? ? printf("%d\n",n);
? ? printf("%f\n",f);
? ? printf("%lf\n",d);
? ??
2015-02-15
舉報
2015-02-16
嚴格地說,在printf中float和double都應該用%f來格式化,因為在傳入參數(shù)時float會被提升為double,而printf中%f就是用來表示double的。
不過一些編譯器也不把%lf視作錯誤而已。
注意:printf中%f的含義和scanf中是不一樣的!在scanf中確實是用%f代表float,用%lf代表double。
2015-02-16
%f用是單精度,而%lf是雙精度