Zitat von
Shaman:
Hoi
Machs doch grad richtig mathematisch
Delphi-Quellcode:
type
TDigit = 0..9;
TDigits = array of TDigit;
procedure NumToDigits(Number: Integer; var Digits: TDigits);
var
I: Integer;
begin
if Number = 0 then
begin
SetLength(Digits, 1);
Digits[0]:= 0;
end else
begin
Number:= Abs(Number);
SetLength(Digits, Trunc(Ln(Number) / Ln(10)) + 1);
I:= 0;
repeat
Digits[I]:= Number mod 10;
Number:= Number div 10;
Inc(I);
until Number = 0;
end;
end;
Gruss
Shaman
und noch etwas kürzer (und nicht in umgekehrter reihenfolge
)...
Delphi-Quellcode:
procedure NumToDigits(Number: Integer; var Digits: TDigits);
var
i: integer;
begin
setLength(Digits, length(IntToStr(Number)));
for i := 0 to high(Digits) do begin
Digits[high(Digits) - i] := Number mod 10;
Number := Number div 10;
end;
end;