|
The PresentValue() function calculates
the total amount that future investments are worth currently. Its syntax is:
|
Extended __fastcall PresentValue(const Extended Rate,
int NPeriods,
const Extended Payment,
const Extended FutureValue,
TPaymentTime PaymentTime);
Here is an example:
//---------------------------------------------------------------------------
#include <vcl.h>
#include <math.hpp>
#pragma hdrstop
#include "Exercise.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmExercise *frmExercise;
//---------------------------------------------------------------------------
__fastcall TfrmExercise::TfrmExercise(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmExercise::btnCalculateClick(TObject *Sender)
{
Extended Present, Future, Rate, Payments;
int Periods;
Future = StrToFloat(edtFutureValue->Text);
Payments = StrToFloat(edtMonthlyPayment->Text);
Rate = StrToFloat(edtInterestRate->Text) / 12;
Periods = StrToInt(edtPeriods->Text);
// Apply the function
Present = PresentValue(Rate / 100, Periods,
-Payments, -Future, ptStartOfPeriod);
// Display the payment
edtPresentValue->Text = FloatToStrF(Present, ffCurrency, 8, 2);
}
//---------------------------------------------------------------------------
void __fastcall TfrmExercise::btnCloseClick(TObject *Sender)
{
PostQuitMessage(0);
}
//---------------------------------------------------------------------------