public static function PHPExcel_Calculation_Financial::PV in Loft Data Grids 7.2
Same name and namespace in other branches
- 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Financial.php \PHPExcel_Calculation_Financial::PV()
* PV * * Returns the Present Value of a cash flow with constant payments and interest rate (annuities). * *
Parameters
float $rate Interest rate per period: * @param int $nper Number of periods * @param float $pmt Periodic payment (annuity) * @param float $fv Future Value * @param int $type Payment type: 0 = at the end of each period, 1 = at the beginning of each period * @return float
File
- vendor/
phpoffice/ phpexcel/ Classes/ PHPExcel/ Calculation/ Financial.php, line 1781
Class
- PHPExcel_Calculation_Financial
- PHPExcel_Calculation_Financial
Code
public static function PV($rate = 0, $nper = 0, $pmt = 0, $fv = 0, $type = 0) {
$rate = PHPExcel_Calculation_Functions::flattenSingleValue($rate);
$nper = PHPExcel_Calculation_Functions::flattenSingleValue($nper);
$pmt = PHPExcel_Calculation_Functions::flattenSingleValue($pmt);
$fv = PHPExcel_Calculation_Functions::flattenSingleValue($fv);
$type = PHPExcel_Calculation_Functions::flattenSingleValue($type);
// Validate parameters
if ($type != 0 && $type != 1) {
return PHPExcel_Calculation_Functions::NaN();
}
// Calculate
if (!is_null($rate) && $rate != 0) {
return (-$pmt * (1 + $rate * $type) * ((pow(1 + $rate, $nper) - 1) / $rate) - $fv) / pow(1 + $rate, $nper);
}
else {
return -$fv - $pmt * $nper;
}
}