#include<stdio.h>
float fun_1(float a,int point)
{
float b,c; //函数须知:fun_1(需精确的数,1/需精确的位数)
b = a*point;
c = b + 0.5;
int f = c;
return (float)f/point;
}
int main()
{
printf("%f",fun_1(1.41666,100));
}
加了0.5该进位就进位,然后把不需要精确的数用float转int丢掉就好了。
至于为什么输入100,其实是可以转化为0.01的,但考虑会多算一步,就没有这样用了。