69,369
社区成员
发帖
与我相关
我的任务
分享
float fun(float h)
{
long t;
int flag = 1;
if (h < 0) {
flag = -1;
h = -h;
}
t = (h * 1000 + 5) / 10;
return (float)flag * t / 100;
}
float fun(float h){
int t;
t=(h+0.005)*100;
return t/100.0;
}
//Round(1.234,2) = 1.23
//Round(1.234,0) = 1.0
//Round(123.4,-1) = 120.0
double Round(double dVal, short iPlaces) {
double dRetval;
double dMod = 0.0000001;
if (dVal<0.0) dMod=-0.0000001;
dRetval=dVal;
dRetval+=(5.0/pow(10.0,iPlaces+1.0));
dRetval*=pow(10.0,iPlaces);
dRetval=floor(dRetval+dMod);
dRetval/=pow(10.0,iPlaces);
return(dRetval);
}
double round(double dVal, short iPlaces) //iPlaces>=0
{
unsigned char s[20];
double dRetval;
sprintf(s,"%.*lf",iPlaces,dVal);
sscanf(s,"%lf",&dRetval);
return (dRetval);
}