Filter null values in PRODUCT() function, as they don't affect the calculation in any way, and actually require additional code handling if they're present within the calculation itself
This commit is contained in:
parent
4df236a688
commit
db4dac3de9
|
|
@ -102,29 +102,27 @@ class Operations
|
|||
*/
|
||||
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 {
|
||||
if (is_numeric($arg)) {
|
||||
$returnValue *= $arg;
|
||||
}
|
||||
} else {
|
||||
return ExcelError::VALUE();
|
||||
}
|
||||
}
|
||||
|
||||
// Return
|
||||
if ($returnValue === null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $returnValue;
|
||||
return (float) $returnValue;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -49,17 +49,29 @@ return [
|
|||
-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],
|
||||
];
|
||||
|
|
|
|||
Loading…
Reference in New Issue