KoolReport's Forum

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

CSVDataSource: Format number with decimals (2) problem #108

Open bysystem opened this topic on on Sep 12, 2017 - 2 comments

bysystem commented on Sep 12, 2017

Dear support team,

I have a csv file with dutzends of semicolon separated values (here is an example of the important part):

Auftnr;Wert;...; 1230336806;1587,80;...; 1230336032;181,25 ;...; 1230336032;370,07 ;...;

  • As you can see the column "Wert" is a number (decimals) with 2 numbers aftrer comma, so I've declared these field in my setup as follows:

    public function settings() {

      return array(
    	"dataSources"=>array(
    		"csv_adums"=>array(
    		'class' => '\koolreport\datasources\CSVDataSource',
    		'filePath' => '016',
    		'fieldSeparator' => ';',
    		)
    	)
      );
    

    }

    public function setup() {

    $this->src('csv_adums')
    	
    ->pipe(new ColumnMeta(array(
          "Wert"=>array(
    "align"=>"right",
              "type"=>"number",
              "prefix"=>"",
    		"suffix"=>"",
    		"decimals"=>2,
    		"thousandSeparator"=>".",
    		"decimalPoint"=>",",
          )
    )))	
    	
    ->pipe(new Pivot(array(
    	"dimensions" => array(
    		//"column" => "FakdatZBCP",
    		"row" => "Sgrp, NameWarenem, Auftrg, Produktname,"
    	),
    	"aggregates" => array(
    		"sum" => "AuftrM, Wert",
    	)
    )))
    ->pipe($this->dataStore('Pivot.ADums')); 		
    

    }

Her is my view:

		<?php
			PivotTable::create(array(
			  "dataStore"=>$this->dataStore('Pivot.ADums'),

			  "measures" => array(
				"AuftrM - sum",
				"Wert - sum",
			  ),
				  
			  "headerMap" => array(
				"AuftrM - sum" => "&sum; Menge",
				"Wert - sum" => "&sum; Umsatz",
			  ),
			 
			  "rowCollapseLevels" => array(0,1,2),
			  "columnCollapseLevels" => array(1,2),
			  
			  "totalName" => '<div align="right"><strong>GESAMT</strong></div>'
			 
			));
		?>  

But in my PivotTable the summarized "Wert"-values are shown only with 123,00 (instead of 123,45). So all the aggregates deliver wrong results!.

If I activate the "error_reporting(0);" I get the following notice:

Notice: A non well formed numeric value encountered in C:\xampp\htdocs\AutoRep_Nikon\koolreport\core\Utility.php on line 60.

Important remarks:

  1. I'm using KoolReport Vers. 1.34.9.
  2. I've downloaded the new version 1.47.3 and copied substituted the existing koolreport folder >> I got a blank page in the front end. So I rolled back to the vers. 1.34.9!

Any idea how to format the number into the wright way?

Kind regards,

KoolReport commented on Sep 12, 2017

By default the number use the "." to separate decimals. In your CSV, the number is separated by comma. To solve this issue. you can do this:

->pipe(new Custom(function($data){
    $data["Wert"] = trim(str_replace(",",".",$data["Wert"]));
    return $data;
}))
bysystem commented on Sep 12, 2017

Works like a charme!

Thx a lot!!!

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
solved

Pivot