KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Numbers with commas not allowed in sum footer. #3313

Open iWorQ Systems opened this topic on on Jul 2 - 1 comments

iWorQ Systems commented on Jul 2

We are having an issue when a number comes in formatted with commas ex: 2,500 to be in the footer as a sum value.

when we do the sum it is getting the error

Warning: A non-numeric value encountered in /iworq/iworq/vendor/koolreport/core/src/core/DataStore.php on line 564

I have a band aid fix of doing

 /**
     * Return the sum of a field
     * 
     * Examples: $totalSales = $dataStore->sum("saleAmount");
     * 
     * @param string $colName Name of column you want to sum
     * 
     * @return float Sum of column
     */
    public function sum($colName)
    {
        $sum = 0;
        foreach ($this->rows as $row) {
            if(!is_int($row[$colName])){
                $sum += (int) str_replace(',', '', $row[$colName]);
            } else {
                $sum += $row[$colName];
            }
        }
        return $sum;
    }

But we update our composer often and was wondering if we could get a more permanent fix to this. Thanks

Sebastian Morales commented on Jul 3

Another solution is to converting the column value from string to number in the report setup and set its meta's "decimalPoint" and "thousandSeparator" for formatted display instead:

https://www.koolreport.com/docs/processes/custom/

https://www.koolreport.com/docs/processes/map/

https://www.koolreport.com/docs/processes/columnmeta/

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

DataGrid