The decimal rounding occurs automatically in generated csv file. #3084

Closed
opened 2024-03-08 05:44:36 +00:00 by giwonn · 1 comment

Hi,
I generate the .csv file using XLSX.utils.

my data format is as below.

const arr = [
  [ 'name', 'cost' ],
  [ 'a', 1234.123456 ],
  [ 'b', 12345.123456 ],
];

I converted list value using aoa_to_sheet().
So I got a XLSX.Worksheet format data as below.

  • code
const workBook = XLSX.utils.book_new();

const arr = [
  [ 'name', 'cost' ],
  [ 'a', 1234.123456 ],
  [ 'b', 12345.123456 ],
];
const workSheet = XLSX.utils.aoa_to_sheet(arr);

console.log(workSheet);
  • console.log result
    It doesn't appear to round the numeric data.
    무제.png

  • csv result
    But when I open csv file, some numeric data is rounded.
    무제2.png

At the decimal point, if the total length of the exponent part and the mantissa part exceeds 10, rounding seems to occur.

As far as I know, adding a z property keeps the decimal point.
But when I checked these interfaces, it seemed that these options were not supported.

Is there any other way but for me to add z property myself?

Thanks

Hi, I generate the .csv file using `XLSX.utils`. my data format is as below. ```js const arr = [ [ 'name', 'cost' ], [ 'a', 1234.123456 ], [ 'b', 12345.123456 ], ]; ``` I converted list value using `aoa_to_sheet()`. So I got a `XLSX.Worksheet` format data as below. - **code** ```js const workBook = XLSX.utils.book_new(); const arr = [ [ 'name', 'cost' ], [ 'a', 1234.123456 ], [ 'b', 12345.123456 ], ]; const workSheet = XLSX.utils.aoa_to_sheet(arr); console.log(workSheet); ``` - **`console.log` result** It doesn't appear to round the numeric data. ![무제.png](/attachments/a27128a5-5a34-4187-a47b-aed73745d536) - **`csv` result** But when I open csv file, some numeric data is rounded. ![무제2.png](/attachments/196c3dad-ed75-449b-95c5-fe5237ae561d) At the decimal point, if the total length of the exponent part and the mantissa part exceeds 10, rounding seems to occur. As far as I know, adding a `z` property keeps the decimal point. But when I checked these interfaces, it seemed that these options were not supported. Is there any other way but for me to add `z` property myself? Thanks
Owner

SheetJS is matching Excel behavior. To verify this, manually enter the value 12345.123456 in a cell.

The General format typically shows up to 11 characters. The decimal character counts as one character, leaving 10 digits.

This question was asked on our Discord chat. https://discord.com/channels/1039771292859109436/1039788802220232744/1148253979076210788 more details.

If you would like some ideas for workarounds, join the chat and ask.

SheetJS is matching Excel behavior. To verify this, manually enter the value `12345.123456` in a cell. The `General` format typically shows up to 11 characters. The decimal character counts as one character, leaving 10 digits. This question was asked on our Discord chat. https://discord.com/channels/1039771292859109436/1039788802220232744/1148253979076210788 more details. If you would like some ideas for workarounds, join the chat and ask.
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#3084
No description provided.