public static function PHPExcel_Calculation_Financial::NPER 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::NPER()
* NPER * * Returns the number of periods for a cash flow with constant periodic payments (annuities), and interest rate. * *
Parameters
float $rate Interest rate per period: * @param int $pmt Periodic payment (annuity) * @param float $pv Present Value * @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 1500
Class
- PHPExcel_Calculation_Financial
- PHPExcel_Calculation_Financial
Code
public static function NPER($rate = 0, $pmt = 0, $pv = 0, $fv = 0, $type = 0) {
$rate = PHPExcel_Calculation_Functions::flattenSingleValue($rate);
$pmt = PHPExcel_Calculation_Functions::flattenSingleValue($pmt);
$pv = PHPExcel_Calculation_Functions::flattenSingleValue($pv);
$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) {
if ($pmt == 0 && $pv == 0) {
return PHPExcel_Calculation_Functions::NaN();
}
return log(($pmt * (1 + $rate * $type) / $rate - $fv) / ($pv + $pmt * (1 + $rate * $type) / $rate)) / log(1 + $rate);
}
else {
if ($pmt == 0) {
return PHPExcel_Calculation_Functions::NaN();
}
return (-$pv - $fv) / $pmt;
}
}