Fix for DOLLARDE() and DOLLARFR() with negative dollar values
Additional argument validations
This commit is contained in:
parent
5ab3cbc8db
commit
f577dde178
|
|
@ -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.
|
||||||
|
|
|
||||||
|
|
@ -960,21 +960,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 array\\|string\\.$#"
|
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\AccruedInterest\\:\\:atMaturity\\(\\) should return float\\|string but returns array\\|string\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\Financial;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\Financial;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
|
@ -40,18 +41,24 @@ class Dollar
|
||||||
*/
|
*/
|
||||||
public static function decimal($fractionalDollar = null, $fraction = 0)
|
public static function decimal($fractionalDollar = null, $fraction = 0)
|
||||||
{
|
{
|
||||||
$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) {
|
||||||
return Functions::DIV0();
|
return Functions::DIV0();
|
||||||
}
|
}
|
||||||
|
|
||||||
$dollars = floor($fractionalDollar);
|
$dollars = ($fractionalDollar < 0.0) ? ceil($fractionalDollar) : floor($fractionalDollar);
|
||||||
$cents = fmod($fractionalDollar, 1);
|
$cents = fmod($fractionalDollar, 1);
|
||||||
$cents /= $fraction;
|
$cents /= $fraction;
|
||||||
$cents *= 10 ** ceil(log10($fraction));
|
$cents *= 10 ** ceil(log10($fraction));
|
||||||
|
|
@ -76,18 +83,24 @@ class Dollar
|
||||||
*/
|
*/
|
||||||
public static function fractional($decimalDollar = null, $fraction = 0)
|
public static function fractional($decimalDollar = null, $fraction = 0)
|
||||||
{
|
{
|
||||||
$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