How to format a string with 3 houses?

Asked

Viewed 303 times

0

I have a code that concatenates the results typed in edits, I am assigning a 0 for each reading for the values stay like this:

Result: 030/060/090/

More when I have a value that already has 3 decimal places then I would like to keep only 3 houses.

Result: 030/060/090/0120/

procedure TfrmCadastroPedido.Button1Click(Sender: TObject);
 var
     i: integer;
begin
      //fazer a leitura de componentes edits com um nome especifico
      for i := 0 to ComponentCount - 1 do
      begin

         if (Copy((Components[i].Name),1,7) = 'edPrazo') and (Components[i].Tag = 1) then
         begin
            if TEdit(Components[i]).Text <> '0' then
             begin
                PrazoParcelasNF :=  PrazoParcelasNF + '0' + TEdit(Components[i]).Text  + '/' ;
             end;
         end;
      end;

       Memo1.Lines.Add(PrazoParcelasNF);

end;

1 answer

2


Just add :

PrazoParcelasNF :=  PrazoParcelasNF + Format('%3.3d', [StrToInt(TEdit(Components[i]).Text)]) + '/';

Browser other questions tagged

You are not signed in. Login or sign up in order to post.