Summing negative values doesn't work

Created on 15 February 2012, almost 13 years ago
Updated 28 February 2024, 9 months ago

I wanted to sum a column that has positive and negative values, and it just added the absolute values. The field is a decimal field, and I configured it to use "Total (Currency)".

For example, if the values are 300, 200, -50, it would summarize as 550 instead of 450.

I changed line 208 in file views_summarize.module from
$total += (float) preg_replace('/[^0-9\.]/', '', $val);
to
$total += (float) preg_replace('/[^-0-9\.]/', '', $val);
adding the "-" to the expression and that seemed to fix it.

I'm not a PHP expert, just at the hacking level and don't totally grok RegEx, so this might not be kosher but it works for me.

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.71.5 2024