Skip to content

Commit 3a6009d

Browse files
committed
Recalibrate for Significance=0
Very peculiar implementation in Excel. PhpSpreadsheet will match it: - FLOOR(8,0) is #DIV/0. This already matched, and is the only result I understand. - CEILING(8,0) is 0 (already matched) - FLOOR.MATH(8,0) is 0 (changed to match) - FLOOR.PRECISE(8,0) is 0 (changed to match) - CEILING.MATH(8,0) is 0 (already matched) - CEILING.PRECISE(8,0) is 0 (already matched)
1 parent 39511e0 commit 3a6009d

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/PhpSpreadsheet/Calculation/MathTrig/Floor.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ public static function math(mixed $number, mixed $significance = null, mixed $mo
8989
return $e->getMessage();
9090
}
9191

92+
if (empty($significance * $number)) {
93+
return 0.0;
94+
}
9295
if ($checkSigns) {
9396
if (($number > 0 && $significance < 0) || ($number < 0 && $significance > 0)) {
9497
return ExcelError::VALUE();
@@ -146,6 +149,9 @@ public static function precise($number, $significance = 1)
146149
} catch (Exception $e) {
147150
return $e->getMessage();
148151
}
152+
if (!$significance) {
153+
return 0.0;
154+
}
149155

150156
return self::argumentsOkPrecise((float) $number, (float) $significance);
151157
}

tests/data/Calculation/MathTrig/FLOORMATH.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[-4, '-2.5, 2'],
99
[2, '2.5, -2'],
1010
[0.0, '0.0, 1'],
11-
['#DIV/0!', '123.456, 0'],
11+
'corrected with PR 4466' => [0.0, '123.456, 0'],
1212
[1.5, '1.5, 0.1'],
1313
[0.23, '0.234, 0.01'],
1414
[123, '123.456'],

tests/data/Calculation/MathTrig/FLOORPRECISE.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[-4, '-2.5, 2'],
99
[2, '2.5, -2'],
1010
[0.0, '0.0, 1'],
11-
['#DIV/0!', '123.456, 0'],
11+
'corrected with PR 4446' => [0.0, '123.456, 0'],
1212
[1.5, '1.5, 0.1'],
1313
[0.23, '0.234, 0.01'],
1414
[123, '123.456'],

0 commit comments

Comments
 (0)