Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
### Fixed

- Fix ROUNDUP and ROUNDDOWN for floating-point rounding error [#1404](https://github.com/PHPOffice/PhpSpreadsheet/pull/1404)
- Fix ROUNDUP and ROUNDDOWN for negative number [#1417](https://github.com/PHPOffice/PhpSpreadsheet/pull/1417)

## [1.11.0] - 2020-03-02

Expand Down
8 changes: 2 additions & 6 deletions src/PhpSpreadsheet/Calculation/MathTrig.php
Original file line number Diff line number Diff line change
Expand Up @@ -1065,9 +1065,7 @@ public static function ROUNDUP($number, $digits)

if ((is_numeric($number)) && (is_numeric($digits))) {
if ($number < 0.0) {
$significance = pow(10, (int) $digits);

return floor($number * $significance) / $significance;
return round($number - 0.5 * pow(0.1, $digits), $digits, PHP_ROUND_HALF_DOWN);
}

return round($number + 0.5 * pow(0.1, $digits), $digits, PHP_ROUND_HALF_DOWN);
Expand All @@ -1093,9 +1091,7 @@ public static function ROUNDDOWN($number, $digits)

if ((is_numeric($number)) && (is_numeric($digits))) {
if ($number < 0.0) {
$significance = pow(10, (int) $digits);

return ceil($number * $significance) / $significance;
return round($number + 0.5 * pow(0.1, $digits), $digits, PHP_ROUND_HALF_UP);
}

return round($number - 0.5 * pow(0.1, $digits), $digits, PHP_ROUND_HALF_UP);
Expand Down
10 changes: 10 additions & 0 deletions tests/data/Calculation/MathTrig/ROUNDDOWN.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@
2.26 + 2.94,
2,
],
[
-4.44,
-4.4400,
2,
],
[
-5.20,
-2.26 - 2.94,
2,
],
[
'#VALUE!',
'ABC',
Expand Down
10 changes: 10 additions & 0 deletions tests/data/Calculation/MathTrig/ROUNDUP.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,21 @@
4.4400,
2,
],
[
-4.44,
-4.4400,
2,
],
[
5.20,
2.26 + 2.94,
2,
],
[
-5.20,
-2.26 - 2.94,
2,
],
[
'#VALUE!',
'ABC',
Expand Down