Datatables query column sum

0

I'm sorry I'm new to PHP and I'm doing Datatables it adds to the value of the column but I can not round the value it gives me with many decimals attached the script that is used to configure the sum

    <script type="text/javascript">

    $('#sampleTable').DataTable( {
        "footerCallback": function ( row, data, start, end, display ) {
            var api = this.api(), data;

            // 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
            total = api
                .column( 3 )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );

            // Total over this page
            pageTotal = api
                .column( 3, { page: 'current'} )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );

            // Update footer
            $( api.column( 3 ).footer() ).html(
                 '$'+pageTotal +' ( $'+ total +' total)'
            );
        }
    } );


</script>
    
asked by Julio 02.07.2018 в 15:30
source

0 answers