0

This is my values that I am getting in datatable.

Cuenta  Nombre Cuenta       Oct18   Dec18   Sep19   Oct19   M$      M%  A$      A%
11      Activos Liquidos    5732,12 6950,89 5879,21 5965,02 85,82   1.4 232,91  4.06   

When exporting the excel the data's decimal place gets converted to 5732.12 6950.89 ..etc. I need to preserve the decimal I am using datatables.

I used this code:

{
      extend: 'excel',
      exportOptions: {
          columns: ':visible',
          format: {
              body: function(data, row, column, node) {
                  data = $('<p>' + data + '</p>').text();
                  return $.isNumeric(data.replace(',', '.')) ? data.replace(',', '.') : data;
              }
          }
      }
  }

But it changes my 4.06 to 4,06 which is incorrect. How to achieve this? Thank you.

Update :

This is the value I am getting in excel

This is what I am getting but completely wrong

Amal
  • 212
  • 2
  • 9

1 Answers1

1

Does this help?

const fields = "11\tActivos Liquidos\t5732,12\t6950,89\t5879,21\t5965,02\t85,82\t1.4\t232,91\t4.06".trim().split("\t")
  .map(fld => /^\d/.test(fld) ? parseFloat(fld.replace(/,/,".")) : fld);
console.log(JSON.stringify(fields))
mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • Where should I paste this ? – Amal Jun 11 '20 at 13:04
  • You need to add `.map(fld => /^\d/.test(fld) ? parseFloat(fld.replace(/,/,".")) : fld);` to the array that holds the values. How you get the array is dependent on the strings. I guessed tab delimited – mplungjan Jun 11 '20 at 13:11