lokopi lokopi - 1 year ago 138
jQuery Question

How to round to 2 decimal places in jquery datatable?

I am using jquery datatable aocolumns to round the specific columns to two decimal places but it seems like i am unable to get the correct regular expression for this or may be their is something wrong with my logic.

"aoColumnDefs": [ {
"aTargets": [ 7 ],
"mRender": function (data, type, full) {
var formmatedvalue = data.replace(/\d+(\.\d{1,2})?/, "")
return formmatedvalue;

The output for that column should be

etc .....

Any possible solution for this?

Answer Source

Use this function:

function (data, type, full) {
     return data.toString().match(/\d+(\.\d{1,2})?/g)[0];

You would be looking for matching the part you need and not to replace.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download