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;
哎,不知道为什么,,

解决方案 »

  1.   

    function Ceil(const X: Extended): Integer;
    begin
      Result := Integer(Trunc(X));
      if Frac(X) > 0 then
        Inc(Result);
    end;
    你传个 double 进来
    Frac(X)的时候,按照Extended来算,就执行Inc(Result)了
      

  2.   

    那我该怎么处理呢,
    我想将获取的比例因子scale*一个整数,然后获取大于等于该结果的最小整数,问题很简单
      

  3.   

    不过Extended要慎用
    还是建议把100*scale这个运算放到外面
    var scale :double; 
    scale := 1.1*100; 这样比较好
      

  4.   

    我也这样用过,
    var scale,temp:real;
    scale := 1.1;
    temp := scale* 100;然后还是照上面的做,但是  inttostr(Ceil(temp)) 后还是老样子,我以前没碰过,现在正在思考简单的对策
      

  5.   

    Description
    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在帮助文件里面找到的!希望对楼主有帮助!
      

  6.   


    Var
    scale :Extended;
    begin
    scale :=1.1;
    edt1.Text:= floattostr(Ceil(100*scale));
    edt2.Text:= floattostr(Ceil(100*1.1));//得出的是110
    end;这种方法可行!
      

  7.   

    晕,我的scale和num(我是假如等于100)都是要手动获取的;;;;;
    Ceil的用法,既然知道要用,肯定知道帮助文档的了
      

  8.   

    trunc直接尾吧给截取了,不行,我再去想想方案
      

  9.   

    晕,trunc+1不就行了?灵活点哇
      

  10.   

    晕,trunc+1不就行了?灵活点哇
      

  11.   

    procedure TForm1.Button1Click(Sender: TObject);
    var scale :double;
    begin
    scale:=1.1;
    Label1.Caption := floattostr(round(100*scale));//得出的是110
    Label2.Caption:= floattostr(round(100*1.1));//得出的是110
    end;
      

  12.   

    根据需要,注意函数的选用
    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