-
-
Notifications
You must be signed in to change notification settings - Fork 8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rounding does not always match Excel's display values #1105
Comments
I've submitted a PR with a potential fix - it'd be good to get your feedback @SheetJSDev |
@SheetJSDev did you get a chance to look through that PR? It'd be great to hear your views 😄 |
(was in the middle of writing a reply 😆) This breaks values which JS would naturally stringify as exponential (like 1.23456789e-7), but this is fairly easy to handle with a regular expression against the string value. Note: there's actually a separate repo for the formatting library https://github.com/sheetjs/ssf with some tests. Curious about how the formats represent the number in question, here are some test files: issue1105.zip. XLSB and standard BIFF8 XLS stores the number as an "Xnum" (IEEE754 double), but older versions of Excel (so-called "BIFF5", like in Excel 95 and Excel 5.0) use a truncated form where the lower 34 bits of the double is zero and one bit is allocated for a 100 modifier. The file |
@SheetJSDev it's all going a bit over my head :-D Looking at those sheets and the |
Looks like this describes the issue well: https://gordonlesti.com/inaccurate-rounding-with-decimal-digits/ That solution is tailored for 2 DPs so I'm going to look at expanding on it tomorrow. |
@SheetJSDev can you take a look at SheetJS/ssf#34 please? I believe this may have fixed the issue |
Adding another case where rounding doesn't match up to Excel: Excel rounds halves away from zero:
Whereas SheetJS rounds halves up:
|
Hi there
For certain cell values the xlsx package yields different formatted display text than Excel.
A full example with a file is available at https://github.com/feverpitch-tom/xlsx-rounding-demo.
For manual reproduction:
Create a spreadsheet with the following three values:
These should be formatted to display at two decimal places, and consequently are displayed as follows in Excel:
When parsed by the xlsx package the w property for each cell, which represents the formatted value, is as follows:
The last value (C1 in the sheet) is 0.01 less than is displayed in Excel.
Thanks
Tom
The text was updated successfully, but these errors were encountered: