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:
oleibman
2024-07-22 08:32:54 -07:00
parent 1b68270f80
commit b6ff857ba7
2 changed files with 14 additions and 2 deletions
@@ -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();
+12
View File
@@ -29,6 +29,18 @@ return [
-250,
5000,
],
[
0.017929869399484,
24.99,
-250,
5000,
],
[
0.016581855,
24.5,
-250,
5000,
],
[
0.016550119066711999,
24,