Now decimal place is 2, I want to change it depending on variable, is it possible?
cell.v = parseFloat(cell.v),
cell.t = 'n';
cell.z = XLSX.SSF._table[2]; // 0.00 -> want to change to 0.000
Now decimal place is 2, I want to change it depending on variable, is it possible?
cell.v = parseFloat(cell.v),
cell.t = 'n';
cell.z = XLSX.SSF._table[2]; // 0.00 -> want to change to 0.000
Just use .toFixed() method:
cell.z = Number(XLSX.SSF._table[2]).toFixed(3);//0.000
Just use a bination of parseFloat()
and toFixed()
:
cell.z = parseFloat(XLSX.SSF._table[2]).toFixed(3);
ParseFloat()
is designed specifically to turn strings into numbers.
As I understand from the ments, the OP wants to write a XLSX file using the js-xlsx
library, with a number rendered with 3 decimals.
I achieve this as follows. I add the format code "0.000" to XLSX.SSF._table
:
XLSX.SSF._table[164] = '0.000'
Then cell.z = '0.000'
should work.
I don't know why the index 164. If there is another format, it goes to 165, then 166, etc.