Return a rounded or truncated amount or only allow whole numbers?
Return a rounded or truncated amount or only allow whole numbers?
{ data: null,
render: function ( data, type, row ) {
return ("$"+data.tbl_pexpenses.cost*data.tbl_pexpenses.quantity);
} }
,
Here is one of my columns. When quantity is a decimal, the function returns (for example) 32.00000000005
This messes up my total that I get and a bunch of other data. I was wondering if the editor has a whole number numeric validator, if there is a way to round the returned data or truncate it or anything?
I also have aoColumnDefs that adds a dollar sign to the front of a different column. Maybe there is something I can do here, as well? Thank you!
"aoColumnDefs": [ {
"aTargets": [2],
"mRender": function ( val, type, all ) {
return ( type === "display" || type === "filter" ) ? "$"+val : val;
}
} ],
This question has an accepted answers - jump to answer
Answers
There is a native javascript method you could use
Math.round(number)
http://www.w3schools.com/jsref/jsref_round.aspThere are plenty of other ways using the native Javascript
Math
likefloor
orceil
.Thank you Daimian!