# Formatting Numbers in Custom Statistics Counters

I have a grid that I load using .load(…“xmlB”), with three headers. The first header is simply labels. The second header is a total of the values in that column, using:

``mygrid.attachHeader("Total,#cspan,#cspan,#cspan,#stat_total")``

The third header is that subtotal, plus a constant. I created a custom statistic counter named stat_sum_const1, as follows:

``mygrid.attachHeader("Net,#cspan,#cspan,#cspan,#stat_sum_const1")``

with script that is based on the sample code:

```mygrid._in_header_stat_sum_krd30=function(tag,index,c){ // shortcut for statistics counter var calck=function(){ // define the function which will be used for calculations var summ=1234567; // set initial counter value this.forEachRow(function(id){ // for each row summ+=this.cells(id,index).getValue()*1; // add row_value }) return summ; } this._stat_in_header(tag,calck,index,c); //call default statistics handler processor }```

In this case, I add 1,234,567 to the total. Then, lastly, I format the column with a thousands separator.

``mygrid.setNumberFormat("0,000",thecolumn,".",",");``

So the totals all work correctly, and the math in my custom addition works too, but the header that uses the standard #stat_total has comma separators, but the #stat_sum_const1 header does not (and has decimals going out much further).

Does anybody know why I get this behavior, and if there is anything I can do to get the formatting of the custom statistic counter to format correctly? Thanks

In your custom function you are returning the summ:
return summ;

In the stat_total counter

[code] var calck=function(){
var summ=0;
this._build_m_order();
var ii = this._m_order?this._m_order[i]:i;
for (var j=0; j<this.rowsBuffer.length; j++){
var v=parseFloat(this._get_cell_value(this.rowsBuffer[j],ii));
summ+=isNaN(v)?0:v;
}

``````	return this._maskArr[ii]?this._aplNF(summ,ii):(Math.round(summ*100)/100);
}[/code]
``````

it’s returning the formatted number:

``return this._maskArr[ii]?this._aplNF(summ,ii):(Math.round(summ*100)/100);``