Skip to content

Commit

Permalink
Fix for DOLLARDE() and DOLLARFR() with negative dollar values
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkBaker committed Feb 11, 2022
1 parent 5ab3cbc commit 0a69aa2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).

### 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)
- 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.
Expand Down
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Calculation/Financial/Dollar.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static function decimal($fractionalDollar = null, $fraction = 0)
return Functions::DIV0();
}

$dollars = floor($fractionalDollar);
$dollars = ($fractionalDollar < 0.0) ? ceil($fractionalDollar) : floor($fractionalDollar);
$cents = fmod($fractionalDollar, 1);
$cents /= $fraction;
$cents *= 10 ** ceil(log10($fraction));
Expand Down Expand Up @@ -87,7 +87,7 @@ public static function fractional($decimalDollar = null, $fraction = 0)
return Functions::DIV0();
}

$dollars = floor($decimalDollar);
$dollars = ($decimalDollar < 0.0) ? ceil($decimalDollar) : floor($decimalDollar);
$cents = fmod($decimalDollar, 1);
$cents *= $fraction;
$cents *= 10 ** (-ceil(log10($fraction)));
Expand Down
10 changes: 10 additions & 0 deletions tests/data/Calculation/Financial/DOLLARDE.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
// fractional_dollar, fraction, result

return [
[
2.5,
1.6,
4,
],
[
-2.5,
-1.6,
4,
],
[
1.125,
1.02,
Expand Down
10 changes: 10 additions & 0 deletions tests/data/Calculation/Financial/DOLLARFR.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
// decimal_dollar, fraction, result

return [
[
1.24,
1.6,
4,
],
[
-1.24,
-1.6,
4,
],
[
1.02,
1.125,
Expand Down

0 comments on commit 0a69aa2

Please sign in to comment.