json2csv
json2csv copied to clipboard
Conditionnal decimal formatter ?
Hello,
How to only apply formatters to some fields ?
In the exemple bellow, the price field should be formatted with a "," separator, but not the average field ?
// data
[{
title: "title",
price: 19.45
average: 2.9849302
}, {
...
}]
// wanted csv
"title";"price";"average"
"title";10,45;"2.9849302"
...
Before, i was using the removed option stringify.
Hi @popod ,
Can you give me a code sample to reproduce the issue?
Here are some code sample
import { Parser } from '@json2csv/plainjs';
import { number as numberFormatter } from '@json2csv/formatters';
const data = [{
name: 'name1',
price: 10.50,
average: 2.8394
}, {
name: 'name2',
price: 8.35,
average: 5.333333
}];
const parser = new Parser({
delimiter: ';',
formatters: {
number: numberFormatter({ separator: ',' }),
}
});
const csv = parser.parse(data);
console.log(csv);
This output is
"name";"price";"average"
"name1";10,5;2,8394
"name2";8,35;5,333333
But i want that the output is
"name";"price";"average"
"name1";10,5;2.8394
"name2";8,35;5.333333
-> price use "," separator for decimal, but average use ".".