牛牛学说话之-浮点数_牛客题霸_牛客网 (nowcoder.com)
#include<stdio.h>
int main()
{
float a;//浮点数也就是小数,有两种定义形式,分别是float和double
scanf("%f",&a);//%f对应float,%lf对应double,就像%d对应整数int一样
printf("%.3f",a);//保留3位小数为.3f,保留1位小数为.1f
return 0;
}
float和double的区别:
float:所占内存小,运行速度快
double:能定义的数范围更大,更精确