diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Operations.php b/src/PhpSpreadsheet/Calculation/MathTrig/Operations.php index 44e1352627..f26da389a7 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Operations.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Operations.php @@ -102,29 +102,27 @@ public static function power($x, $y) */ public static function product(...$args) { + $args = array_filter( + Functions::flattenArray($args), + function ($value) { + return $value !== null; + } + ); + // Return value - $returnValue = null; + $returnValue = (count($args) === 0) ? 0.0 : 1.0; // Loop through arguments - foreach (Functions::flattenArray($args) as $arg) { + foreach ($args as $arg) { // Is it a numeric value? - if (is_numeric($arg) || $arg === null) { - if ($returnValue === null) { - $returnValue = $arg; - } else { - $returnValue *= $arg; - } + if (is_numeric($arg)) { + $returnValue *= $arg; } else { return ExcelError::VALUE(); } } - // Return - if ($returnValue === null) { - return 0; - } - - return $returnValue; + return (float) $returnValue; } /** diff --git a/tests/data/Calculation/MathTrig/PRODUCT.php b/tests/data/Calculation/MathTrig/PRODUCT.php index ab5009535b..657c713c0d 100644 --- a/tests/data/Calculation/MathTrig/PRODUCT.php +++ b/tests/data/Calculation/MathTrig/PRODUCT.php @@ -49,17 +49,29 @@ -2, ], [ - 0, + 31.25, 12.5, null, 2.5, ], [ - 0, + 31.25, 12.5, 2.5, null, ], + [ + 12.5, + 12.5, + null, + null, + ], + [ + 0.0, + null, + null, + null, + ], ['#VALUE!', 1, 'y', 3], [6, 1, '2', 3], ];