In column 17 I have taken total[1]
and divided it by total[0]
. The number is a long decimal. How would I shorten that decimal so that the value in column 17 to only have three decimal places (rounding to the nearest thousandths place if it has more than 3 decimals)
$(document).ready(function() {
$('#battingtbl').DataTable({
"searching": true,
"pageLength": 40,
"scrollX": true,
"paging": false,
"info": false,
drawCallback: () => {
const table = $('#battingtbl').DataTable();
const tableData = table.rows({
search: 'applied'
}).data().toArray();
const totals = tableData.reduce((total, rowData) => {
total[0] += parseFloat(rowData[6]);
total[1] += parseFloat(rowData[8]);
return total;
}, [0, 0]);
$(table.column(6).footer()).text(totals[0]);
$(table.column(8).footer()).text(totals[1]);
$(table.column(17).footer()).text(totals[1] / totals[0]); // I WANT TO ROUND THIS
}
})
});