①引子
以四舍五入,保留两位小数为例,
输入数据:.
理想结果:.46
但是
选取不同的数据类型
会得到不同的小数精度
只能是约等于.46
C语言中
浮点数无法精确存放,
double类型的精度高于float类型。
~
②float类型的精度
floatfun(floath)
{longt;
t=(h*+5)/10;
return(float)t/;}
输入数据:.
原始数据:.001
实际结果:.
~
floatfun(floath)
{intt=(int)(h*+5)/10;
return(float)t/;}
输入数据:.
原始数据:.001
实际结果:.
~
floatfun(floath)
{return(float)(int)(h*+5)/10/;
}
输入数据:.
原始数据:.001
实际结果:.
~
③double类型的精度
doublefun(doubleh)
{longt;
t=(h*+5)/10;
return(double)t/;}
输入数据:.
原始数据:.001
实际结果:.
~
doublefun(doubleh)
{intt=(int)(h*+5)/10;
return(double)t/;}
输入数据:.
原始数据:.001
实际结果:.
~
doublefun(doubleh)
{return(double)(int)(h*+5)/10/;
}
输入数据:.
原始数据:.001
实际结果:.46