Witam
Jak sformatować liczbę aby była poprzedzona zerami?
np:
1 - 000001
2 - 000002
3 - 000003
...
256 - 000256
Witam
Jak sformatować liczbę aby była poprzedzona zerami?
np:
1 - 000001
2 - 000002
3 - 000003
...
256 - 000256
function zeruj_se(liczba:integer):string;
begin
case liczba of
1..9 : result:='00000'+inttostr(liczba);
10..99: result:='0000'+inttostr(liczba);
100..999:result:='000'+inttostr(liczba);
1000..9999:result:='00'+inttostr(liczba);
10000..99999:result:='0'+inttostr(liczba);
else result:=inttostr(liczba);
end;
end;
Przyklad uzycia:
procedure TForm1.FormCreate(Sender: TObject);
begin
caption:=zeruj_se(15161);
end;
albo inaczej:
function dodaj_zera(i:integer, ile:byte):string;
var
a: Integer;
buff : string;
begin
buff := '';
for a := 0 to (ile-length(inttostr(i))) do
begin
buff := buff + '0';
end;
buff := buff + inttostr(i);
end;
powinno działać...
A nie latwiej:
function dodaj_zera(liczba:integer,ile:byte)
begin
result := inttostr(liczba);
while (Length(result)<ile) result:='0'+result;
end;
Chyba powinno się to robić tak:
function zamien(ilosc_miejsc:byte; liczba:integer):string;
begin
result:=Format('%0.'+inttostr(ilosc_miejsc)+'d', [liczba]);
end;
dzięki za zaangażowanie [browar]