Round Pagetotal Footer callback
Round Pagetotal Footer callback
Hello friends.
I write a table with footer callback where I have a series of decimal numbers that add up to 100, adding the total to each one gives me 100.00000003, I would like to be able to round this number so that it does not appear that long, and tried with Math. round, but I could not, I would like to know if any of you could help me I would be very grateful, I am using the following code.
footerCallback: function ( row, data, start, end, display ) {
var api = this.api();
// Remove the formatting to get integer data for summation
var intVal = function ( i ) {
return typeof i === 'string' ?
i.replace(/[\%,]/g, '')*1 :
typeof i === 'number' ?
i : 0;
};
// Total over all pages
if (api.column(6).data().length){
var total = api
.column(6)
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
} ) }
else{ total = 0};
// Total over this page
if (api.column(6).data().length){
var pageTotal = api
.column( 6, { page: 'current'} )
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
} ) }
else{ pageTotal = 0};
$( api.column( 6 ).footer() ).html(
pageTotal +' % '
);
}