how to show separate digit in delphi 7 dbgrid

hi,

i need to separate the number contains in dbgrid (e.g. 45.000.500 instead of 45000500)

how can i do this in delphi 7?

thanks
enshrentkoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Emmanuel PASQUIERFreelance Project ManagerCommented:
function AddPointEvery3Digits(S:String):String;
Var
 L:integer;
begin
 Result:='';
 L:=Length(S);
 While L>3 do
  begin
   Result:='.'+Copy(S,L-2,3)+Result;
   L:=L-3;
   S:=Copy(S,1,L);
  end;
 Result:=S+Result;
end;
0
Geert GOracle dbaCommented:
add the fields to query --> persistent fields
and set the displayformat in the fields to 0,0

or set at runtime
query.fieldbyname('fieldname').DisplayFormat := '0,0';
0
Geert GOracle dbaCommented:
only works for numeric fields
and set the
thousandseparator := '.';

in your app
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Emmanuel PASQUIERFreelance Project ManagerCommented:
ah, yes it's a DBGrid.
0
bokistCommented:
Check this solution :

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
          const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
   st : string;
   sv : variant;
   si : integer;
begin
   with (Sender as TDBGrid), Canvas do
      begin
      if Column.Fieldname = 'my_field_name'  then
         begin
         sv := Column.Field.Value;
         if not (VarIsNull(sv)) then
            begin
            sq := Column.Field.Value;
            if sq < 0 then sq := sq * -1;
            if (sq = 0) or (sq < 0.01) then
               begin
               FillRect(Rect);
               Exit;
            end;
            st := FormatFloat('###.###.###,##;;-', Column.Field.Value);
            if st[1] = ',' then  st := '0' + st
            else  if pos('-,', st) > 0 then  st := '-0' + copy(st,2,10);
            si := round(((Rect.Right - Rect.Left) / 2)) - round(TextWidth(st) / 2);
            TextRect(Rect, Rect.Left + si, Rect.Top+2, st);
         end;  
      end;      
      DefaultDrawColumnCell(Rect, DataCol, Column, State);
   end;  
end;
0
bokistCommented:
Oops, Exit missing after line "TextRect........."
0
Mahdi78Commented:
Check this solution


private
    { Private declarations }
    procedure MyProcedure(Sender: TField; var Text: string;
         DisplayText: Boolean);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.MyProcedure(Sender: TField; var Text: string;
  DisplayText: Boolean);
begin
    Text := FormatFloat('#,##0', Sender.AsFloat );
end;



procedure TForm1.FormCreate(Sender: TObject);
begin
(Table1.FieldByName('MyField') as TField).OnGetText := MyProcedure;
end;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.