5
votes

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.

1
@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.Thunderstruck
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.Andrew Savinykh
@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 :)Thunderstruck

1 Answers

2
votes

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.