Hello community MVD. It follows down script what I created to do financial calculations (financial mathematics).
procedure calculo_juros_composto;
var
PMT, FV, PV, i, n: real;
inicio: integer;
p1, p2: real;
calculou: boolean = false;
begin
PMT := frmCalc.edPMT.value;
FV := frmCalc.edFV.value;
PV := frmCalc.edPV.value;
i := frmCalc.edi.value/100;
n := frmCalc.edn.value;
inicio := strtoint(frmCalc.chk_begin.sqlValue);
if (frmCalc.edPMT.text = '') and (frmCalc.edFV.value = 0) then //calcula PMT com FV = 0
begin
calculou := true;
p1 := power((i + 1),n)-1;
p2 := power((1 + i),(n - inicio)) * i;
PMT := PV/(p1/p2);
frmCalc.edPMT.text := Formatfloat('###,###,#0.00',PMT);
exit;
end;
if (frmCalc.edPV.text = '') and (frmCalc.edFV.value = 0) then //calcula PV com FV = 0
begin
calculou := true;
p1 := power((i + 1),n)-1;
p2 := power((1 + i),(n - inicio)) * i;
PV := PMT/(p2/p1);
frmCalc.edPV.text := Formatfloat('###,###,#0.00',PV);
exit;
end;
if (frmCalc.edFV.text = '') and (frmCalc.edPV.value = 0) then //calcula FV com PV = 0
begin
calculou := true;
p1 := power((i + 1),n)-1;
p2 := i;
FV := PMT * (p1/p2);
frmCalc.edFV.text := Formatfloat('###,###,#0.00',FV);
exit;
end;
if (frmCalc.edPMT.text = '') and (frmCalc.edPV.value = 0) then //calcula PMT com PV = 0
begin
calculou := true;
p1 := power((i + 1),n)-1;
p2 := i;
PMT := FV / (p1/p2);
frmCalc.edPMT.text := Formatfloat('###,###,#0.00',PMT);
exit;
end;
if (frmCalc.edi.text = '') and (frmCalc.edPMT.value = 0) then //calcula i com PMT = 0
begin
calculou := true;
p1 := FV/PV;
p2 := power(p1,(1/n));
i := (p2 - 1)*100;
frmCalc.edi.text := Formatfloat('###,###,#0.00',i);
exit;
end;
if (frmCalc.edn.text = '') and (frmCalc.edPMT.value = 0) then //calcula n com PMT = 0
begin
calculou := true;
p1 := FV/PV;
p2 := i + 1;
n := ln(p1)/ln(p2);
frmCalc.edn.text := Formatfloat('##0',n);
exit;
end;
.......................................................................
if calculou = false then showmessage('o campo a ser calculado deve estar em branco e deve haver um campo com valor = 0 (zero)');
end;
Roberto Alencar