From 39b8dbd0a1fda087d229e3abbcc666275fc3d35a Mon Sep 17 00:00:00 2001 From: Matthias Van Woensel Date: Sun, 4 Dec 2016 16:11:22 +0900 Subject: [PATCH] Adding float cast to MOD function If $a or $b are not strings, you can get an error that fmod needs param 1 ($a) to be of type double. MS Excel does not fall over when you insert an empty string in MOD, so I'm guessing PHPExcel should do the same? --- src/PhpSpreadsheet/Calculation/MathTrig.php | 4 ++-- tests/data/Calculation/MathTrig/MOD.php | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/PhpSpreadsheet/Calculation/MathTrig.php b/src/PhpSpreadsheet/Calculation/MathTrig.php index 1d104c18..9c6b60ec 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig.php @@ -673,8 +673,8 @@ class MathTrig */ public static function MOD($a = 1, $b = 1) { - $a = Functions::flattenSingleValue($a); - $b = Functions::flattenSingleValue($b); + $a = (float) Functions::flattenSingleValue($a); + $b = (float) Functions::flattenSingleValue($b); if ($b == 0.0) { return Functions::DIV0(); diff --git a/tests/data/Calculation/MathTrig/MOD.php b/tests/data/Calculation/MathTrig/MOD.php index e98e41a7..3aded00a 100644 --- a/tests/data/Calculation/MathTrig/MOD.php +++ b/tests/data/Calculation/MathTrig/MOD.php @@ -46,4 +46,9 @@ return [ 1.3, 1.2, ], + [ + '', + 1, + 0, + ], ];