diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fb8791b..975c0ffd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). ### Fixed -- ... +- FLOOR() function accept negative number and negative significance [#1245](https://github.com/PHPOffice/PhpSpreadsheet/pull/1245) ## [1.10.0] - 2019-11-18 diff --git a/src/PhpSpreadsheet/Calculation/MathTrig.php b/src/PhpSpreadsheet/Calculation/MathTrig.php index 30071c2d..fc9211b8 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig.php @@ -301,7 +301,9 @@ class MathTrig return Functions::DIV0(); } elseif ($number == 0.0) { return 0.0; - } elseif (self::SIGN($number) == self::SIGN($significance)) { + } elseif (self::SIGN($significance) == 1) { + return floor($number / $significance) * $significance; + } elseif (self::SIGN($number) == -1 && self::SIGN($significance) == -1) { return floor($number / $significance) * $significance; } diff --git a/tests/data/Calculation/MathTrig/FLOOR.php b/tests/data/Calculation/MathTrig/FLOOR.php index 4b2bd4a2..7d408173 100644 --- a/tests/data/Calculation/MathTrig/FLOOR.php +++ b/tests/data/Calculation/MathTrig/FLOOR.php @@ -12,7 +12,7 @@ return [ -2, ], [ - '#NUM!', + -4, -2.5, 2, ],