Merge pull request #14113 from cinaglia/fix-csv-decimal-places

Retain decimal precision when exporting CSV
This commit is contained in:
Torkel Ödegaard 2018-12-19 11:56:27 +01:00 committed by GitHub
commit 9e92609313
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -73,6 +73,7 @@ describe('file_export', () => {
],
rows: [
[123, 'some_string', 1.234, true],
[1000, 'some_string', 1.234567891, true],
[0o765, 'some string with " in the middle', 1e-2, false],
[0o765, 'some string with "" in the middle', 1e-2, false],
[0o765, 'some string with """ in the middle', 1e-2, false],
@ -89,6 +90,7 @@ describe('file_export', () => {
const expectedText =
'"integer_value";"string_value";"float_value";"boolean_value"\r\n' +
'123;"some_string";1.234;true\r\n' +
'1000;"some_string";1.234567891;true\r\n' +
'501;"some string with "" in the middle";0.01;false\r\n' +
'501;"some string with """" in the middle";0.01;false\r\n' +
'501;"some string with """""" in the middle";0.01;false\r\n' +

View File

@ -41,10 +41,8 @@ function formatSpecialHeader(useExcelHeader) {
function formatRow(row, addEndRowDelimiter = true) {
let text = '';
for (let i = 0; i < row.length; i += 1) {
if (isBoolean(row[i]) || isNullOrUndefined(row[i])) {
if (isBoolean(row[i]) || isNumber(row[i]) || isNullOrUndefined(row[i])) {
text += row[i];
} else if (isNumber(row[i])) {
text += row[i].toLocaleString();
} else {
text += `${QUOTE}${csvEscaped(htmlUnescaped(htmlDecoded(row[i])))}${QUOTE}`;
}