datatables 3: Number format gives wrong output for negative numbers
datatables 3: Number format gives wrong output for negative numbers
Link to test case:
Error messages shown:
Description of problem:
The determiniation of the decimal part fails for negative numbers:
See this debug output with values displayed:
return null == a && (a = ht),
null == i && (i = gt),
{
display: function(e) {e = -1140516
var t, r, n;t = "-", r = 1140516.46, n = ",81032.46"
return "number" != typeof e && "string" != typeof e || "" === e || null === e ? e : (t = (n = "number" == typeof e ? e : parseFloat(e)) < 0 ? "-" : "",e = -1140516
1e11 <= (r = Math.abs(n)) || r < 1e-4 && 0 !== r ? (r = n.toExponential(o).split(/e\+?/))[0] + " x 10<sup>" + r[1] + "</sup>" : isNaN(n) ? k.escapeHtml(e) : (n = n.toFixed(o),r = 1140516.46
r = Math.abs(n),
e = parseInt(n, 10),e = -1140516
n = o ? i + (r - e).toFixed(o).substring(2) : "",r = 1140516.46
(t = 0 === e && 0 === parseFloat(n) ? "" : t) + (l || "") + e.toString().replace(/\B(?=(\d{3})+(?!\d))/g, a) + n + (s || "")))
}
}
},
r is always positive, but the integer val e is negative for negative numbers, so r-e gives a large sum instedd of the decimal part.
Answers
Hi Björn,
Many thanks for your post about this. There is another thread on the topic as well. As noted there I've got a fix committed and in the nightly build. I'm aiming to do a release of the fix either today (if all goes well!), or tomorrow.
Regards,
Allan
Fixed in github already by https://github.com/DataTables/DataTablesSrc/commit/739c4ccc61faef2c5b4f0dcbe628d3c878a1d538
I was using the download builder bootstrap 5.3.8 build.