[FormatFloat('0.0', <frxDBDataset1."pricea">)]
我需要在FASTREPORT里显示的时候保留一位小数,当pricea为100.12的时候是没有问题的,
但是当pricea为100.18的时候,就自动进位了,执行结果为100.2。请问有什么办法不进位,
我需要的显示结果是100.1 或者是否有其他函数可以代替这个函数?

解决方案 »

  1.   

    点字段右键->编辑->文本,设为:
    [Trunc(<frxDBDataset1."字段名">*10)/10]
      

  2.   

    除了楼上这种方法,是否还有其他方法啊?请问format这个函数在FASTREPORT如何使用?是否也可以实现这种效果
      

  3.   

    [FormatFloat('0.0', <frxDBDataset1."pricea">-0.05)]
      

  4.   

    保留的小数位我是让客户自己选择的,也就是'0.0'有可能是'0.00',上述的做法当然也可以在程序外部先做判断,但是觉得还是有点麻烦,有没有更直接一点方法?我一直在查找,FORMAT这个函数是否也可以实现格式化?但是试了都不成功。
      

  5.   

    几种四余五入的方法1.Round(四舍六入五留双)功能说明:对一个实数进行四舍五入。(按照银行家算法) 
    例:
    var
        i, j: Integer;
    begin
        i := Round(1.5); // i等于2
        j := Round(2.5); // j等于2
    end;在Delphi中使用Round函数得到的答案有时与我们所预期的会不太一样:采用的是四舍六入五留双。即当舍或入位大于或小于五时按四舍五入来处理,而当舍或入位等于五时,就要看前面一位是什么,根据奇进偶不进,它总是返回一个偶数值。
    例:            
    i:= Round(11.5)//i等于12
    i:= Round(10.5)//i等于10这种Round其实是按照银行家算法,统计学上一般都用这种算法,比传统的"四舍五入"要科学。
    如果要使用传统的"四舍五入"方法,可以使用下面函数:
    function RoundClassic(R: Real)2.trunc(取得X的整数部分)
    如:trunc(-123.55)=-123, floor(123.55)=1233.ceil(取得大于等于X的最小的整数)如:ceil(-123.55)=-123, ceil(123.15)=1244.floor(取得小于等于X的最大的整数)如:floor(-123.55)=-124,floor(123.55)=123注:floor和ceil是math unit里的函数,使用前要先Uses Math
    function Int(X: Extended): Extended;//取整 注意它返回的是Extended类型它也是浮点型哦
    function Round(X: Extended): Int64;//四舍五入 
    function Trunc(X: Extended): Int64;//将小数无条件舍去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)=124floor 和 ceil 是 math unit 里的函数,使用前要先 Uses Math。
    trunc 和 round 是 system unit 里的函数,缺省就可以用。//真正的四舍五入
    function myround(const yuan: Extended; const pp: Integer): Extended;
    //yuan:原浮点数,PP保留 小数点后第几位
    var
    p,l,m,l2:Longint;
    s:string; // 原浮点数
    sq:string; // 小数点前
    sh:string;//小数点后
    begin
    if yuan=0 then exit;// 原浮点数 0
    if pp<0 then exit; //非法小数点后第几位
    s:=floattostr(yuan);
    p:=pos('.',s);    //小数点位置
    sq:=midstr(s,1,p-1);
    sh:=midstr(s,p+1,length(s)-length(sq)-1);
    l:=length(sh);//小数位数
    l2:=length(sq);//整数位数
    if pp>=l then
       begin//0
        result:=strtofloat(s);
        exit;//比如 11。06 要保留到 小数点后第3位显然 不合理
       end;//
    { if pp=l then   //比如 11。06 要保留到 小数点后第2位不用处理 直接返回
        begin//1
          Result:=s;
          exit;
        end;//1 }
       if pp<l then //比如 11。06 要保留到 小数点后第1位 ,
       begin//2
         m:=strtoint(sh[pp+1]);
         if m>=5 then
         begin
           if pp>=1 then //保留到 小数点后第1,2位
           begin//3
            sh:=midstr(sh,1,pp);
            sh := inttostr(strtoint(sh)+1);
            if length(sh)>pp then
            begin
               sh:= midstr(sh,2,pp);
               sq:= inttostr(strtoint(sq)+1);
            end;
           Result:=strtofloat(sq+'.'+sh);
           exit;
           end//3
           else   //保留到 小数点后第0位
           begin//4
            sq[l2]:=chr(ord(sq[l2])+1);
            Result:=strtofloat(sq);
            exit;
           end;//4
         end
         else
         begin
           if pp>=1 then //保留到 小数点后第1,2位
           begin//3
            sh:=midstr(sh,1,pp);
            Result:=strtofloat(sq+'.'+sh);
           exit;
           end//3
           else   //保留到 小数点后第0位
           begin//4
            Result:=strtofloat(sq);
            exit;
           end;//4
         end;
       end;//2
    end;动态报表数据格式可用self.frxReport1.LoadFromFile('reports\统计明细表.fr3');
    TfrxMemoView(frxReport1.FindObject('Memo13')).DisplayFormat.FormatStr :='%2.2f';//Memo13为你自己的字段,保留2位