Fix ROUNDUP and ROUNDDOWN for negative number

Closes #1417
This commit is contained in:
n-longcape 2020-03-12 12:37:07 +09:00 committed by Adrien Crivelli
parent e2f87e8b7a
commit f9f9f4cacf
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
4 changed files with 23 additions and 6 deletions

View File

@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
### Fixed ### Fixed
- Fix ROUNDUP and ROUNDDOWN for floating-point rounding error [#1404](https://github.com/PHPOffice/PhpSpreadsheet/pull/1404) - 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)
- Fix loading styles from vmlDrawings when containing whitespace [#1347](https://github.com/PHPOffice/PhpSpreadsheet/issues/1347) - Fix loading styles from vmlDrawings when containing whitespace [#1347](https://github.com/PHPOffice/PhpSpreadsheet/issues/1347)
- Fix incorrect behavior when removing last row [#1365](https://github.com/PHPOffice/PhpSpreadsheet/pull/1365) - Fix incorrect behavior when removing last row [#1365](https://github.com/PHPOffice/PhpSpreadsheet/pull/1365)
- MATCH with a static array should return the position of the found value based on the values submitted [#1332](https://github.com/PHPOffice/PhpSpreadsheet/pull/1332) - MATCH with a static array should return the position of the found value based on the values submitted [#1332](https://github.com/PHPOffice/PhpSpreadsheet/pull/1332)

View File

@ -1139,9 +1139,7 @@ class MathTrig
if ((is_numeric($number)) && (is_numeric($digits))) { if ((is_numeric($number)) && (is_numeric($digits))) {
if ($number < 0.0) { if ($number < 0.0) {
$significance = pow(10, (int) $digits); return round($number - 0.5 * pow(0.1, $digits), $digits, PHP_ROUND_HALF_DOWN);
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);
@ -1167,9 +1165,7 @@ class MathTrig
if ((is_numeric($number)) && (is_numeric($digits))) { if ((is_numeric($number)) && (is_numeric($digits))) {
if ($number < 0.0) { if ($number < 0.0) {
$significance = pow(10, (int) $digits); return round($number + 0.5 * pow(0.1, $digits), $digits, PHP_ROUND_HALF_UP);
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);

View File

@ -71,6 +71,16 @@ return [
2.26 + 2.94, 2.26 + 2.94,
2, 2,
], ],
[
-4.44,
-4.4400,
2,
],
[
-5.20,
-2.26 - 2.94,
2,
],
[ [
'#VALUE!', '#VALUE!',
'ABC', 'ABC',

View File

@ -66,11 +66,21 @@ return [
4.4400, 4.4400,
2, 2,
], ],
[
-4.44,
-4.4400,
2,
],
[ [
5.20, 5.20,
2.26 + 2.94, 2.26 + 2.94,
2, 2,
], ],
[
-5.20,
-2.26 - 2.94,
2,
],
[ [
'#VALUE!', '#VALUE!',
'ABC', 'ABC',