浮点型
-
单精度浮点型
单精度浮点型 float 4Byte 32Bit 7可表示有效范围
(如果定义一个float类型的数值,需要在最后边加一个f,否则会当做double来处理)
-
双精度浮点型
双精度浮点型 double 8Byte 64Bit 15`16可表示有效范围
注意这里说的有效范围是所有书,包括大于1的那个位置
-
长双精度浮点型
长双精度浮点型 long double 8Byte 64Bit
格式化输出
-
单精度浮点型
%f
-
双精度浮点型
%lf
%.*lf 强制输出小数点后多少位
-
长双精度浮点型
%Lf
(注意: 字母L是大写)
示例
#include<stdio.h>
int main()
{
float f = 3.1415926f;
printf("%f \n",f);
//调试输出 3.142693
double d = 3.1415926;
printf("%lf \n",d);
//调试输出 3.142693
//%.* 强制输出小数点后多少位
printf("%.15lf \n",d);
//调试输出 3.142692600000000
return 0;
}