现在用DBGrid,他有一个属性footer,是求和的。小数位控制是在DisplayFormat中的,但是现在把小数位写成8位,明细中是8位,汇总后小数位是8位,但是后4位总是0,就是自动截断了后面四位。试了一下,还是不知道怎么控制?哪位有高招?

解决方案 »

  1.   

    ftFloat, ftCurrency:
                  if Footer.DisplayFormat <> '' then
                    Result := FormatFloat(Footer.DisplayFormat, v)
                  else
                  with Field as TFloatField do
                  begin
                    FmtStr := DisplayFormat;
                    if FmtStr = '' then
                    begin
                      if Currency then
                      begin
                        Format := ffCurrency;
                        Digits := CurrencyDecimals;
                      end
                      else begin
                        Format := ffGeneral;
                        Digits := 0;
                      end;
                      Result := FloatToStrF(v, Format, Precision, Digits);
                    end else
                      Result := FormatFloat(FmtStr, v);
                  end;
              end;
            end;
      

  2.   

    换种方法求汇总,
    用sql语句好了,我都是这样做的,至于你那种方法,我没用过select 科目﹐成绩 from table1 where ...
    union 
    select ''合计'' as 科目 ,round(sum(成绩),8) as 成绩 from table1 where ...用round函数来保留8小数
      

  3.   

    (ADOQuery1.fieldbyname('系数') as Tfloatfield).DisplayFormat:='#,##0.#######0';
      

  4.   

    DisplayFormat,round我都用过了,我这个是控制Dbgrid最后一行自动求和的小数位的,我发现最多有4位,如果是8位的话,最后就是3。22220000,系统自动把后面的截断了。就是这个意思,不知道大家明白没有?