Skip to content

Commit 523afe5

Browse files
authored
Merge pull request #4107 from oleibman/pr848
RATE Function Permits Floating Point NPER
2 parents ae2c3ea + b6ff857 commit 523afe5

File tree

2 files changed

+14
-2
lines changed
  • src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic
  • tests/data/Calculation/Financial

2 files changed

+14
-2
lines changed

src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Interest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public static function rate(
165165
$guess = ($guess === null) ? 0.1 : Functions::flattenSingleValue($guess);
166166

167167
try {
168-
$numberOfPeriods = CashFlowValidations::validateInt($numberOfPeriods);
168+
$numberOfPeriods = CashFlowValidations::validateFloat($numberOfPeriods);
169169
$payment = CashFlowValidations::validateFloat($payment);
170170
$presentValue = CashFlowValidations::validatePresentValue($presentValue);
171171
$futureValue = CashFlowValidations::validateFutureValue($futureValue);
@@ -193,7 +193,7 @@ public static function rate(
193193
return $close ? $rate : ExcelError::NAN();
194194
}
195195

196-
private static function rateNextGuess(float $rate, int $numberOfPeriods, float $payment, float $presentValue, float $futureValue, int $type): string|float
196+
private static function rateNextGuess(float $rate, float $numberOfPeriods, float $payment, float $presentValue, float $futureValue, int $type): string|float
197197
{
198198
if ($rate == 0.0) {
199199
return ExcelError::NAN();

tests/data/Calculation/Financial/RATE.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@
2929
-250,
3030
5000,
3131
],
32+
[
33+
0.017929869399484,
34+
24.99,
35+
-250,
36+
5000,
37+
],
38+
[
39+
0.016581855,
40+
24.5,
41+
-250,
42+
5000,
43+
],
3244
[
3345
0.016550119066711999,
3446
24,

0 commit comments

Comments
 (0)