Stop decimal rounding in generated excel file #3003
Labels
No Label
DBF
Dates
Defined Names
Features
Formula
HTML
Images
Infrastructure
Integration
International
ODS
Operations
Performance
PivotTables
Pro
Protection
Read Bug
SSF
SYLK
Style
Write Bug
good first issue
No Milestone
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: sheetjs/sheetjs#3003
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hi,
I generate the .xlsx file using 'XLSX.write' function. This is used in the React application. This is the write function code snippet.
const wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'binary' });
That wb object include some of the data like SS below.
After I generated the .xlsx file the D2 cell = 7581185.560000000 and D3 cell = 12005729.810000000. I need to get the exact value in the generated .xlsx file, which I pass through the wb object and it should be the Number type.
How can I accomplish this requirement ?
Thanks
Excel itself is rounding the value. To confirm this, try:
The attached file was generated by running the lines in the JavaScript console in a browser window.
To see what the file contains, go to https://docs.sheetjs.com/docs/#preview-a-workbook-on-your-device . In the live codeblock, within the "Import Button" block, add a line to log the worksheet:
Using the file picker in the example, if you pick the file, the contents look like:
If you manually try entering
7581185.559999999
in Excel, it automatically rounds to7581185.55999999
(one less digit) and the value stored in the file is7581185.5599999903
Excel will show what you expect if you use the exact value Excel stores:
This will be added to the documentation
Yes, It's rounding up the value Excel itself.
Excel can only display numbers up to 15 digits in a cell, and any number longer than this will show 0 instead of the number after the 15th digit.
Reference: [https://support.microsoft.com/en-gb/office/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3]
Thanks
https://docs.sheetjs.com/docs/miscellany/errors/#some-decimal-values-are-rounded let us know if we should include anything else in that note
Hi @sheetjs,
If I enter manually 7581185.559999999 value as a number with 9 decimal points in Excel it's become 7581185.559999990(It's Excel behavior). But If I generate through the XLSX passing that value it's gives 7581185.560000000. It's behave differently. Is there any reason for that one?
https://docs.sheetjs.com/docs/miscellany/errors#some-decimal-values-are-rounded
7581185.55999999
is "15 decimal digits of precision".7581185.559999999 is "16 decimal digits of precision":
IEEE754 and JS supports values in this range with an additional digit of precision:
You can calculate this range by digging into the bit-level representation of these values -- feel free to join our chat at https://sheetjs.com/chat if you want to discuss this further.
Each value will either be "rounded down" to
7581185.55999999
or "rounded up" to the next supported value7581185.56000000
.If you would like to see a test: https://jsfiddle.net/234wopks/
Each JS value is either rounded up or rounded down.