uses StrUtils, Math;
function formatnum(mNumber: string):string;
var
m:integer;
TemStr:string;
begin
Result:='';
for m:=1 to Length(mNumber) do
begin
if mNumber[m]='.' then
Result:=Result+'.'
else
Result:=Result+IntToStr(StrToIntDef(mNumber[m], 0));
end;
while Pos('0', Result) = 1 do Delete(Result, 1, 1);
if Pos('.', Result )<= 0 then Result := Result + '.';
TemStr:=StrRight(Result,'.');
while Copy(TemStr, Length(TemStr), 1) = '0' do Delete(TemStr, Length(TemStr), 1);
Result:=StrLeft(Result,'.')+'.'+TemStr;
if Copy(Result, Length(Result), 1) = '.' then Delete(Result, Length(Result), 1);
if Result[1]='.' then Result:='0'+Result;
if (Result = '') then Result := '0';
end;
function StrLeft(const mStr: string; mDelimiter: string): string;
begin
Result := Copy(mStr, 1, Pos(mDelimiter, mStr) - 1);
end;
function StrRight(const mStr: string; mDelimiter: string): string;
begin
if Pos(mDelimiter, mStr) <= 0 then
Result := ''
else Result := Copy(mStr, Pos(mDelimiter, mStr) + Length(mDelimiter), MaxInt);
end;
function InfiniteAdd(mNumberA, mNumberB: string): string;
var
I: Integer;
T: Integer;
begin
Result := '';
if Pos('.', mNumberA) <= 0 then mNumberA := mNumberA + '.';
if Pos('.', mNumberB) <= 0 then mNumberB := mNumberB + '.';
I := Max(Length(StrLeft(mNumberA, '.')), Length(StrLeft(mNumberB, '.')));
mNumberA := DupeString('0', I - Length(StrLeft(mNumberA, '.'))) + mNumberA;
mNumberB := DupeString('0', I - Length(StrLeft(mNumberB, '.'))) + mNumberB;
T := Max(Length(StrRight(mNumberA, '.')), Length(StrRight(mNumberB, '.')));
mNumberA := mNumberA + DupeString('0', T - Length(StrRight(mNumberA, '.')));
mNumberB := mNumberB + DupeString('0', T - Length(StrRight(mNumberB, '.')));
I := I + T + 1;
T := 0;
for I := I downto 1 do
if [mNumberA[I], mNumberB[I]] <> ['.'] then begin
T := StrToIntDef(mNumberA[I], 0) + T;
T := StrToIntDef(mNumberB[I], 0) + T;
Result := IntToStr(T mod 10) + Result;
T := T div 10;
end else Result := '.' + Result;
if T <> 0 then Result := IntToStr(T mod 10) + Result;
while Pos('0', Result) = 1 do Delete(Result, 1, 1);
while Copy(Result, Length(Result), 1) = '0' do
Delete(Result, Length(Result), 1);
if Copy(Result, Length(Result), 1) = '.' then
Delete(Result, Length(Result), 1);
if Copy(Result, 1, 1) = '.' then Result := '0' + Result;
if (Result = '') then Result := '0';
end;
function InfiniteMult(mNumberA, mNumberB: string): string;
function fMult(mNumber: string; mByte: Byte): string;
var
I: Integer;
T: Integer;
begin
Result := '';
T := 0;
for I := Length(mNumber) downto 1 do begin
T := StrToIntDef(mNumber[I], 0) * mByte + T;
Result := IntToStr(T mod 10) + Result;
T := T div 10;
end;
if T <> 0 then Result := IntToStr(T mod 10) + Result;
end;
var
I: Integer;
vDecimal: Integer;
T: string;
begin
Result := '';
if Pos('.', mNumberA) <= 0 then mNumberA := mNumberA + '.';
if Pos('.', mNumberB) <= 0 then mNumberB := mNumberB + '.';
vDecimal := Length(StrRight(mNumberA, '.')) + Length(StrRight(mNumberB, '.'));
mNumberA := StrLeft(mNumberA, '.') + StrRight(mNumberA, '.');
mNumberB := StrLeft(mNumberB, '.') + StrRight(mNumberB, '.');
T := '';
for I := Length(mNumberB) downto 1 do begin
Result := InfiniteAdd(Result, fMult(mNumberA, StrToIntDef(mNumberB[I], 0)) + T);
T := T + '0';
end;
Insert('.', Result, Length(Result) - vDecimal + 1);
while Pos('0', Result) = 1 do Delete(Result, 1, 1);
while Copy(Result, Length(Result), 1) = '0' do
Delete(Result, Length(Result), 1);
if Copy(Result, Length(Result), 1) = '.' then
Delete(Result, Length(Result), 1);
if Copy(Result, 1, 1) = '.' then Result := '0' + Result;
if (Result = '') then Result := '0';
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Edit3.Text := InfiniteMult(Edit1.Text, Edit2.Text);
end;