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 - 5 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/

iWorQ Systems commented on Jul 22

Is there a way I can use the "type" => "num-fmt" rather than number so I can properly sort my column?

Sebastian Morales commented on Jul 24

Would you pls post parts of your report setup and view code which relate to the sum footers? We will try to find an elegant solution for you.

iWorQ Systems commented on Jul 24

I figured it out. I just had to set my column def for that column to be num-fmt and it showed correctly and was able to still be sorted.

Sebastian Morales commented on Jul 25

Would you mind sharing parts of your code relating to the format problem so that other customers in the future could share your knowledge. Tks,

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