diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Sum.php b/src/PhpSpreadsheet/Calculation/MathTrig/Sum.php index 7b1ffa9eba..37070e2434 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Sum.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Sum.php @@ -18,7 +18,7 @@ class Sum * * @param mixed ...$args Data values * - * @return float|string + * @return float|int|string */ public static function sumIgnoringStrings(...$args) { @@ -47,7 +47,7 @@ public static function sumIgnoringStrings(...$args) * * @param mixed ...$args Data values * - * @return float|string + * @return float|int|string */ public static function sumErroringStrings(...$args) { @@ -56,10 +56,7 @@ public static function sumErroringStrings(...$args) $aArgs = Functions::flattenArrayIndexed($args); foreach ($aArgs as $k => $arg) { // Is it a numeric value? - if (is_numeric($arg) || empty($arg)) { - if (is_string($arg)) { - $arg = (int) $arg; - } + if (is_numeric($arg)) { $returnValue += $arg; } elseif (is_bool($arg)) { $returnValue += (int) $arg; diff --git a/tests/data/Calculation/MathTrig/SUM.php b/tests/data/Calculation/MathTrig/SUM.php index 0c54613e2a..ad2c78e0ce 100644 --- a/tests/data/Calculation/MathTrig/SUM.php +++ b/tests/data/Calculation/MathTrig/SUM.php @@ -5,7 +5,9 @@ [52, 5, 15, 30, 2], [53.1, 5.7, 15, 30, 2.4], [52.1, 5.7, '14', 30, 2.4], + [52.2, 5.7, '14.1', 30, 2.4], [38.1, 5.7, 'X', 30, 2.4], // error if entered in formula, but not in cell + [38.1, 5.7, '', 30, 2.4], // error if entered in formula, but not in cell [38.1, 5.7, null, 30, 2.4], [38.1, 5.7, false, 30, 2.4], [39.1, 5.7, true, 30, 2.4], diff --git a/tests/data/Calculation/MathTrig/SUMLITERALS.php b/tests/data/Calculation/MathTrig/SUMLITERALS.php index fd184ebd50..0ea5938617 100644 --- a/tests/data/Calculation/MathTrig/SUMLITERALS.php +++ b/tests/data/Calculation/MathTrig/SUMLITERALS.php @@ -5,7 +5,9 @@ [52, '5, 15, 30, 2'], [53.1, '5.7, 15, 30, 2.4'], [52.1, '5.7, "14", 30, 2.4'], + [52.2, '5.7, "14.1", 30, 2.4'], ['#VALUE!', '5.7, "X", 30, 2.4'], // error if entered in formula, but not in cell + ['#VALUE!', '5.7, "", 30, 2.4'], // error if entered in formula, but not in cell [38.1, '5.7, , 30, 2.4'], [38.1, '5.7, false, 30, 2.4'], [39.1, '5.7, true, 30, 2.4'],