json2csv
json2csv copied to clipboard
Allows to conserve zero for decimal
Hi,
Is it possible to conserve 2 decimal as if it is zeros ? Because this will prevent Excel to convert some decimal numbers to dates on CSV import.
For exemple, the decimal number "10.5" could be converted by Excel as "10.05.2025".
This kind of things was possible with older versions when the stringify option was available.
Repro code
import { Parser } from '@json2csv/plainjs';
import { number as numberFormatter } from '@json2csv/formatters';
const data = [{
name: 'name1',
price: 10.50
}, {
name: 'name2',
price: 9.55
}];
const parser = new Parser({
delimiter: ';',
formatters: {
number: numberFormatter({ decimal: 2 }),
}
});
const csv = parser.parse(data);
console.log(csv);
Output
"name";"price"
"name1";10.5
"name2";9.55
But i want
"name";"price"
"name1";10.50 -> conserve the .50 !
"name2";9.55