[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 836
  • Last Modified:

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
0
enshrentko
Asked:
enshrentko
  • 2
  • 2
  • 2
  • +1
1 Solution
 
epasquierCommented:
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 GruwezOracle 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 GruwezOracle dbaCommented:
only works for numeric fields
and set the
thousandseparator := '.';

in your app
0
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

 
epasquierCommented:
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now