How does Excel show decimal values correctly although no information is stored in the worksheet.xml and styles.xml about the precision of the decimal?
Asked Answered
A

1

6

Here are the steps I am following to examine the behavior:

1# Create an Excel(xlsx) file, put 1234.56789 in a cell, save it.
2# Extract the .xlsx file, see the sheet1.xml and styles.xml files.

In the xl/worksheets/Sheet1.xml you will see following:

<sheetData><row r="1" spans="1:1" x14ac:dyDescent="0.25"><c r="A1" s="1"
<v>25778.567889999998</v>
</c></row></sheetData>

And there is no information in the Styles.xml about the precision of the original number which is 1234.56789.

How does Excel show the original value when we open it in MS Excel?
How does it reconstruct that original number although there is no information in the extracted files?

Note that I did not change the cell format type or anything, so the cell format is General.

I understand that because Excel is storing the number as floating point, it cannot save the value to perfect accuracy, what I can't understand is how it retains the original value when I open that in MS Excel. I am facing an issue regarding reading Excel files using OpenXML SDK, but before asking about that issue I am looking for answer to this more fundamental question.

Anamariaanamnesis answered 14/1, 2015 at 17:17 Comment(3)
@pnuts sorry that was a mistake, removing it. I fell into this question while trying to parse such decimal values but losing precision, was using OpenXML sdk with C#, so mistakenly added that tag although not relevant with the question.Anamariaanamnesis
Could that be a coincidence? There probably some display algorithm that sees a lot of 9s in the end and cut them off rounding up at the same time.Philippic
@pnuts thanks for the note. Yes I know you were on one of the two other related questions I posted today. No one seems to answer any of the questions yet. I'm going to put a bounty, need 1 more point to be eligible to do that :)Anamariaanamnesis
G
1

It just limits input precision to 15 digits, e.g. try to put 25778.567889999955 in cell and see it is immediately converted (in Excel itself) to 25778.5678899999 and 1.23456789123456789 becomes 1.23456789123456. For more details on numeric representation internals and how it affects calculations see this wonderful wikipedia article.

Gumma answered 14/1, 2015 at 18:57 Comment(3)
Yes I know that, and this answer does not relate to the scenario I stated above. My Original entry is 9 digits, with precision of 5. And the sheet1.xml stores as 17 digit floating point which is inaccurate ofcourse, with precision of 14. My question was How does MS excel reconstruct that exact 9 digit number from that 17 digit value in sheet.xml? If that had rounded only to the limit of 15 digits, the original value of 9 digit would not have been reconstructed.Anamariaanamnesis
Thanks for the article link btw!Anamariaanamnesis
@Anamariaanamnesis 25778.567889999998 rounded to 15 digits gives 25778.5678900000 or 25778.56789 without trailing zeroesGumma

© 2022 - 2024 — McMap. All rights reserved.