Merge branch 'master' into Issue-2551-Array-Ready-Function-Financial
# Conflicts: # phpstan-baseline.neon # src/PhpSpreadsheet/Calculation/Financial/Dollar.php
This commit is contained in:
commit
8818a7d620
|
|
@ -49,6 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
- Fix bug with `DOLLARDE()` and `DOLLARFR()` functions when the dollar value is negative [Issue #2578](https://github.com/PHPOffice/PhpSpreadsheet/issues/2578) [PR #2579](https://github.com/PHPOffice/PhpSpreadsheet/pull/2579)
|
||||||
- Fix partial function name matching when translating formulae from Russian to English [Issue #2533](https://github.com/PHPOffice/PhpSpreadsheet/issues/2533) [PR #2534](https://github.com/PHPOffice/PhpSpreadsheet/pull/2534)
|
- Fix partial function name matching when translating formulae from Russian to English [Issue #2533](https://github.com/PHPOffice/PhpSpreadsheet/issues/2533) [PR #2534](https://github.com/PHPOffice/PhpSpreadsheet/pull/2534)
|
||||||
- Various bugs related to Conditional Formatting Rules, and errors in the Xlsx Writer for Conditional Formatting [PR #2491](https://github.com/PHPOffice/PhpSpreadsheet/pull/2491)
|
- Various bugs related to Conditional Formatting Rules, and errors in the Xlsx Writer for Conditional Formatting [PR #2491](https://github.com/PHPOffice/PhpSpreadsheet/pull/2491)
|
||||||
- Xlsx Reader merge range fixes.
|
- Xlsx Reader merge range fixes.
|
||||||
|
|
|
||||||
|
|
@ -965,21 +965,6 @@ parameters:
|
||||||
count: 1
|
count: 1
|
||||||
path: src/PhpSpreadsheet/Calculation/Financial/Depreciation.php
|
path: src/PhpSpreadsheet/Calculation/Financial/Depreciation.php
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Cannot cast mixed to int\\.$#"
|
|
||||||
count: 2
|
|
||||||
path: src/PhpSpreadsheet/Calculation/Financial/Dollar.php
|
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Parameter \\#1 \\$number of function floor expects float, mixed given\\.$#"
|
|
||||||
count: 2
|
|
||||||
path: src/PhpSpreadsheet/Calculation/Financial/Dollar.php
|
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Parameter \\#1 \\$x of function fmod expects float, mixed given\\.$#"
|
|
||||||
count: 2
|
|
||||||
path: src/PhpSpreadsheet/Calculation/Financial/Dollar.php
|
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\AccruedInterest\\:\\:atMaturity\\(\\) should return float\\|string but returns mixed\\.$#"
|
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\AccruedInterest\\:\\:atMaturity\\(\\) should return float\\|string but returns mixed\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\Financial;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\Financial;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\TextData\Format;
|
use PhpOffice\PhpSpreadsheet\Calculation\TextData\Format;
|
||||||
|
|
||||||
|
|
@ -50,11 +51,17 @@ class Dollar
|
||||||
return self::evaluateArrayArguments([self::class, __FUNCTION__], $fractionalDollar, $fraction);
|
return self::evaluateArrayArguments([self::class, __FUNCTION__], $fractionalDollar, $fraction);
|
||||||
}
|
}
|
||||||
|
|
||||||
$fractionalDollar = Functions::flattenSingleValue($fractionalDollar);
|
try {
|
||||||
$fraction = (int) Functions::flattenSingleValue($fraction);
|
$fractionalDollar = FinancialValidations::validateFloat(
|
||||||
|
Functions::flattenSingleValue($fractionalDollar) ?? 0.0
|
||||||
|
);
|
||||||
|
$fraction = FinancialValidations::validateInt(Functions::flattenSingleValue($fraction));
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
// Validate parameters
|
// Additional parameter validations
|
||||||
if ($fractionalDollar === null || $fraction < 0) {
|
if ($fraction < 0) {
|
||||||
return Functions::NAN();
|
return Functions::NAN();
|
||||||
}
|
}
|
||||||
if ($fraction == 0) {
|
if ($fraction == 0) {
|
||||||
|
|
@ -92,18 +99,24 @@ class Dollar
|
||||||
return self::evaluateArrayArguments([self::class, __FUNCTION__], $decimalDollar, $fraction);
|
return self::evaluateArrayArguments([self::class, __FUNCTION__], $decimalDollar, $fraction);
|
||||||
}
|
}
|
||||||
|
|
||||||
$decimalDollar = Functions::flattenSingleValue($decimalDollar);
|
try {
|
||||||
$fraction = (int) Functions::flattenSingleValue($fraction);
|
$decimalDollar = FinancialValidations::validateFloat(
|
||||||
|
Functions::flattenSingleValue($decimalDollar) ?? 0.0
|
||||||
|
);
|
||||||
|
$fraction = FinancialValidations::validateInt(Functions::flattenSingleValue($fraction));
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
// Validate parameters
|
// Additional parameter validations
|
||||||
if ($decimalDollar === null || $fraction < 0) {
|
if ($fraction < 0) {
|
||||||
return Functions::NAN();
|
return Functions::NAN();
|
||||||
}
|
}
|
||||||
if ($fraction == 0) {
|
if ($fraction == 0) {
|
||||||
return Functions::DIV0();
|
return Functions::DIV0();
|
||||||
}
|
}
|
||||||
|
|
||||||
$dollars = floor($decimalDollar);
|
$dollars = ($decimalDollar < 0.0) ? ceil($decimalDollar) : floor($decimalDollar);
|
||||||
$cents = fmod($decimalDollar, 1);
|
$cents = fmod($decimalDollar, 1);
|
||||||
$cents *= $fraction;
|
$cents *= $fraction;
|
||||||
$cents *= 10 ** (-ceil(log10($fraction)));
|
$cents *= 10 ** (-ceil(log10($fraction)));
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,16 @@
|
||||||
// fractional_dollar, fraction, result
|
// fractional_dollar, fraction, result
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
[
|
||||||
|
2.5,
|
||||||
|
1.6,
|
||||||
|
4,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
-2.5,
|
||||||
|
-1.6,
|
||||||
|
4,
|
||||||
|
],
|
||||||
[
|
[
|
||||||
1.125,
|
1.125,
|
||||||
1.02,
|
1.02,
|
||||||
|
|
@ -38,6 +48,11 @@ return [
|
||||||
1.1200000000000001,
|
1.1200000000000001,
|
||||||
32,
|
32,
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'#VALUE!',
|
||||||
|
'Not A Number',
|
||||||
|
0,
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'#DIV/0!',
|
'#DIV/0!',
|
||||||
1.2344999999999999,
|
1.2344999999999999,
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,16 @@
|
||||||
// decimal_dollar, fraction, result
|
// decimal_dollar, fraction, result
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
[
|
||||||
|
1.24,
|
||||||
|
1.6,
|
||||||
|
4,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
-1.24,
|
||||||
|
-1.6,
|
||||||
|
4,
|
||||||
|
],
|
||||||
[
|
[
|
||||||
1.02,
|
1.02,
|
||||||
1.125,
|
1.125,
|
||||||
|
|
@ -38,6 +48,11 @@ return [
|
||||||
1.375,
|
1.375,
|
||||||
32,
|
32,
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'#VALUE!',
|
||||||
|
'Not A Number',
|
||||||
|
0,
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'#DIV/0!',
|
'#DIV/0!',
|
||||||
1.2344999999999999,
|
1.2344999999999999,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue