在DBGrid的DrawColumnCell事件中加入:
with TDBGrid(Sender) do
begin
{格式化浮点数显示}
if(DataSource.DataSet.IsEmpty = true) then else
if(Column.Field.AsString = '') then else
if(Column.Field.DataType <> ftFloat) then else
if(Column.Field.IsNull <> true) then
begin
vRect := Rect;
vText := PChar(format('%.2f',[StrToFloat(Column.Field.AsString)]));
vRect.Right := vRect.Right -2;
Canvas.FillRect(Rect);
DrawText(Canvas.Handle, vText, StrLen(vText), vRect, DT_RIGHT or DT_SINGLELINE);
// Canvas.TextOut(Rect.Right-Canvas.TextWidth(strtmp)-2, Rect.Top+1, strtmp);
end;
end;
包你满意,给分吧!