var scale :double;
scale := 1.1;
Label1.Caption := floattostr(Ceil(100*scale))会发现现实的是111;1)如果
Label1.Caption:= floattostr(Ceil(100*1.1));//得出的是110程序开发时候就是因为上面类似原因导致我数据我采用了方式一本来需要110数据的,现在确获取的是111..
不太清楚为什么,就算是精度问题,难道他这1.1不是float-point;
哎,不知道为什么,,
scale := 1.1;
Label1.Caption := floattostr(Ceil(100*scale))会发现现实的是111;1)如果
Label1.Caption:= floattostr(Ceil(100*1.1));//得出的是110程序开发时候就是因为上面类似原因导致我数据我采用了方式一本来需要110数据的,现在确获取的是111..
不太清楚为什么,就算是精度问题,难道他这1.1不是float-point;
哎,不知道为什么,,
begin
Result := Integer(Trunc(X));
if Frac(X) > 0 then
Inc(Result);
end;
你传个 double 进来
Frac(X)的时候,按照Extended来算,就执行Inc(Result)了
我想将获取的比例因子scale*一个整数,然后获取大于等于该结果的最小整数,问题很简单
还是建议把100*scale这个运算放到外面
var scale :double;
scale := 1.1*100; 这样比较好
var scale,temp:real;
scale := 1.1;
temp := scale* 100;然后还是照上面的做,但是 inttostr(Ceil(temp)) 后还是老样子,我以前没碰过,现在正在思考简单的对策
Call Ceil to obtain the lowest integer greater than or equal to X. The absolute value of X must be less than MaxInt. For example:
Ceil(-2.8) = -2
Ceil(2.8) = 3
Ceil(-1.0) = -1在帮助文件里面找到的!希望对楼主有帮助!
Var
scale :Extended;
begin
scale :=1.1;
edt1.Text:= floattostr(Ceil(100*scale));
edt2.Text:= floattostr(Ceil(100*1.1));//得出的是110
end;这种方法可行!
Ceil的用法,既然知道要用,肯定知道帮助文档的了
var scale :double;
begin
scale:=1.1;
Label1.Caption := floattostr(round(100*scale));//得出的是110
Label2.Caption:= floattostr(round(100*1.1));//得出的是110
end;
floor 直接往小的取,比如 floor(-123.55)=-124,floor(123.55)=123
trunc 直接切下整数,比如 trunc(-123.55)=-123, floor(123.55)=123
ceil 直接往大的取,比如 ceil(-123.55)=-123, ceil(123.55)=124
round 计算四舍五入,比如 round(-123.55)=-124,round(123.55)=124