Fix bug #1626 where values of 0 were "rounded" up/down as if they were not 0 (#1627)

* Fix bug where values of 0 were "rounded" up/down as if they were not 0
This commit is contained in:
Flinsch 2020-12-10 21:49:53 +01:00 committed by GitHub
parent 9289ab11b2
commit 1f2f2c79da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 1 deletions

View File

@ -81,7 +81,8 @@ and this project adheres to [Semantic Versioning](https://semver.org).
### Fixed ### Fixed
- PrintArea causes exception [#1544](https://github.com/phpoffice/phpspreadsheet/pull/1544) - PrintArea causes exception [#1544](https://github.com/phpoffice/phpspreadsheet/pull/1544)
- ROUNDUP and ROUNDDOWN return incorrect results for values of 0 [#1627](https://github.com/phpoffice/phpspreadsheet/pull/1627)
- Calculation/DateTime Failure With PHP8 [#1661](https://github.com/phpoffice/phpspreadsheet/pull/1661) - Calculation/DateTime Failure With PHP8 [#1661](https://github.com/phpoffice/phpspreadsheet/pull/1661)
- Reader/Gnumeric Failure with PHP8 [#1662](https://github.com/phpoffice/phpspreadsheet/pull/1662) - Reader/Gnumeric Failure with PHP8 [#1662](https://github.com/phpoffice/phpspreadsheet/pull/1662)
- ReverseSort bug, exposed but not caused by PHP8 [#1660](https://github.com/phpoffice/phpspreadsheet/pull/1660) - ReverseSort bug, exposed but not caused by PHP8 [#1660](https://github.com/phpoffice/phpspreadsheet/pull/1660)

View File

@ -1108,6 +1108,10 @@ class MathTrig
$digits = Functions::flattenSingleValue($digits); $digits = Functions::flattenSingleValue($digits);
if ((is_numeric($number)) && (is_numeric($digits))) { if ((is_numeric($number)) && (is_numeric($digits))) {
if ($number == 0.0) {
return 0.0;
}
if ($number < 0.0) { if ($number < 0.0) {
return round($number - 0.5 * 0.1 ** $digits, $digits, PHP_ROUND_HALF_DOWN); return round($number - 0.5 * 0.1 ** $digits, $digits, PHP_ROUND_HALF_DOWN);
} }
@ -1134,6 +1138,10 @@ class MathTrig
$digits = Functions::flattenSingleValue($digits); $digits = Functions::flattenSingleValue($digits);
if ((is_numeric($number)) && (is_numeric($digits))) { if ((is_numeric($number)) && (is_numeric($digits))) {
if ($number == 0.0) {
return 0.0;
}
if ($number < 0.0) { if ($number < 0.0) {
return round($number + 0.5 * 0.1 ** $digits, $digits, PHP_ROUND_HALF_UP); return round($number + 0.5 * 0.1 ** $digits, $digits, PHP_ROUND_HALF_UP);
} }

View File

@ -1,6 +1,11 @@
<?php <?php
return [ return [
[
0,
0,
2,
],
[ [
662, 662,
662.78999999999996, 662.78999999999996,

View File

@ -1,6 +1,11 @@
<?php <?php
return [ return [
[
0,
0,
2,
],
[ [
663, 663,
662.78999999999996, 662.78999999999996,