Math Functions: Straight Line Depreciation



The VCL provides another function used to calculate the depreciation of an item. This time, the depreciation is considered on one period of the life of the item. The function used, SLNDepreciation(), is:

Extended __fastcall SLNDepreciation(const Extended Cost,
				    const Extended Salvage,
				    int Life);

The Cost argument is the original amount paid for an item (refrigerator, mechanics toolbox, high-volume printer, etc). The Life parameter represents the period during which the asset is (or was) useful; it is usually measured in years. The Salvage parameter, also called the scrap value, is the value that the item will have (or is having) at the end of Life.

To perform this operation, the VCL uses the following formula:

void __fastcall TForm1::btnCalculateClick(TObject *Sender)
	Extended Depreciation, Cost, Salvage;
	int Life;

	Cost = StrToFloat(edtCost->Text);
	Salvage = StrToFloat(edtSalvage->Text);
	Life = StrToInt(edtLife->Text);
	Depreciation = SLNDepreciation(Cost, Salvage, Life);

	edtDepreciation->Text = FloatToStrF(Depreciation, ffCurrency, 8, 2);

Here is an example of running this code:





Home Copyright © 2010-2016, FunctionX