var
  a : double;
begin
with myQuery do
begin
  close;
  Sql.Clear;
  Sql.Add('select sum(a8) as aaaa from table1 where...' );
  Open
  a := FieldByName('aaaa').AsFloat;
  Close;
end;
end; 

解决方案 »

  1.   

    这样显示还是好多位小数,我想将变量xy:=1236.369654中的数据直接显示在caption中,并使其保留2位小数。应该怎么做呢?
      

  2.   

    var
      a : double;
    begin
    with myQuery do
    begin
      close;
      Sql.Clear;
      Sql.Add('select Round(sum(a8),2) as aaaa from table1 where...' );
      Open
      a := FieldByName('aaaa').AsFloat;
      Close;
    end;
      

  3.   

    var
      a : double;
    begin
    with myQuery do
    begin
      close;
      Sql.Clear;
      Sql.Add('select sum(a8) as aaaa from table1 where...' );
      Open
      a := FieldByName('aaaa').AsFloat;
      caption=Format('%8.2f',[a]);
      Close;
    end;
    end; 
      

  4.   

    同意: rannado() 
    也可以考虑CONVERT或CAST
      

  5.   

    Format('%8.2f',[a]);
      
      

  6.   

    同意w8u(晌马)
    如果不怕麻烦
    可以用pos函数定位字符串中的小数点,然后用copy函数取子串