# Is it possible to do summation based on actual values?

Is it possible to do summation based on actual values in dhtmxGrid?

For example, we have three row of “0.4” in a column called “MarketValue”

MarketValue:
0.4
0.4
0.4
Total: 1.2

We need to round up numbers in the column “MarketValue” to no decimal places, and we’d like to use their real and actual values for the mathematical calculation, so that their total value matches calculations done by Microsoft spreadsheet:

Expected: 0.4 + 0.4 + 0.4 = 1.2 -> round up to no decimal places = 1
Actual result and NOT desired: 0 + 0 + 0 = 0 -> round up to no decimal places = 0

There is a related post at viewtopic.php?f=2&t=20380 from year 2011. Do we have any solutions right now?

Unfortunately the only way is to create your own custom math logic, nad get the needed number iterating through the cells values.

Thank you so much for the quick response and I really appreciate it.

Would you please show me how I can create a custom math logic for the total calculation with respect to header column filters, such as grid.attachHeader(#numeric_filter)?

The RAR file attached containing a sample of this issue. Notice that the all three records under the column “Coupon” are “0.49”, but they are round down to “0” with no decimal precisions. Their total is incorrectly calculated as “0”.

Many thanks.
Complete Demo Total Calculations.rar (129 KB)

In case of using the number formatting column types you will have to create your own custom exCell type.
For example you may try to use the following “ronround” exCell:

``` function eXcell_ronround(cell){ eXcell_ron.call(this, cell); eXcell_ronround.prototype.setValue=function(val){ orig_val=val if (val === 0){} else if (!val||val.toString()._dhx_trim() == ""){ this.setCValue("&nbsp;"); return this.cell._clearCell=true; } this.cell._clearCell=false; this.setCValue(val?this.grid._aplNF(val, this.cell._cellIndex):"0"); } this.getValue=function(){ return orig_val; } } eXcell_ronround.prototype = new eXcell;```