mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-31 12:40:00 +00:00
RATE Function Permits Floating Point NPER
Suggested by PR #848 from @markkimsal. The RATE calculation had already been corrected, so that part of the PR was unnecessary, however one of the tests included a floating point value for Number of Periods, which Excel permits. PhpSpreadsheet till now expected that parameter to be an integer. This is trivially changed with some tests added.
This commit is contained in:
@@ -165,7 +165,7 @@ class Interest
|
||||
$guess = ($guess === null) ? 0.1 : Functions::flattenSingleValue($guess);
|
||||
|
||||
try {
|
||||
$numberOfPeriods = CashFlowValidations::validateInt($numberOfPeriods);
|
||||
$numberOfPeriods = CashFlowValidations::validateFloat($numberOfPeriods);
|
||||
$payment = CashFlowValidations::validateFloat($payment);
|
||||
$presentValue = CashFlowValidations::validatePresentValue($presentValue);
|
||||
$futureValue = CashFlowValidations::validateFutureValue($futureValue);
|
||||
@@ -193,7 +193,7 @@ class Interest
|
||||
return $close ? $rate : ExcelError::NAN();
|
||||
}
|
||||
|
||||
private static function rateNextGuess(float $rate, int $numberOfPeriods, float $payment, float $presentValue, float $futureValue, int $type): string|float
|
||||
private static function rateNextGuess(float $rate, float $numberOfPeriods, float $payment, float $presentValue, float $futureValue, int $type): string|float
|
||||
{
|
||||
if ($rate == 0.0) {
|
||||
return ExcelError::NAN();
|
||||
|
||||
@@ -29,6 +29,18 @@ return [
|
||||
-250,
|
||||
5000,
|
||||
],
|
||||
[
|
||||
0.017929869399484,
|
||||
24.99,
|
||||
-250,
|
||||
5000,
|
||||
],
|
||||
[
|
||||
0.016581855,
|
||||
24.5,
|
||||
-250,
|
||||
5000,
|
||||
],
|
||||
[
|
||||
0.016550119066711999,
|
||||
24,
|
||||
|
||||
Reference in New Issue
Block a user