Skip to content

Update Sum.php #4441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/PhpSpreadsheet/Calculation/MathTrig/Sum.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
Expand Down Expand Up @@ -47,12 +47,19 @@
*/
public static function sumErroringStrings(mixed ...$args): float|int|string|array
{
$returnValue = 0;
$returnValue = $maxDecimals = 0;
// Loop through the arguments
$aArgs = Functions::flattenArrayIndexed($args);
foreach ($aArgs as $k => $arg) {
// Is it a numeric value?
if (is_numeric($arg)) {
// We count the number of signs after aim
$parts = explode('.', (string)$arg);
if (isset($parts[1])) {
$decimals = strlen(rtrim($parts[1], '0'));
$maxDecimals = max($maxDecimals, $decimals);
}

Check failure on line 62 in src/PhpSpreadsheet/Calculation/MathTrig/Sum.php

View workflow job for this annotation

GitHub Actions / phpcs

Whitespace found at end of line
$returnValue += $arg;
} elseif (is_bool($arg)) {
$returnValue += (int) $arg;
Expand All @@ -64,8 +71,11 @@
}
}

return $returnValue;
return $maxDecimals
? round($returnValue, $maxDecimals)
: $returnValue;

}

Check failure on line 78 in src/PhpSpreadsheet/Calculation/MathTrig/Sum.php

View workflow job for this annotation

GitHub Actions / phpcs

Function closing brace must go on the next line following the body; found 1 blank lines before brace

/**
* SUMPRODUCT.
Expand Down
Loading