Numbers stored in .XML file

Copper Contributor

Dears,

 

I'm having a problem with numbers while trying to upload my .XML files to another programs. While using excel file numbers are shown as for example: 99999,999 but when I open file in notepad for example number is shown as: 99999.998999999996. 

If I edit file (in notepad) and remove additional digits it looks alright, but when i'm trying to save a file with new numbers (99999,999) it goes back to previous number (99999.998999999996). I tried basically everything I could find. I did cell formating, i've tried to copy and paste those numbers, chat gpt and i've enabled "set precision as displayed" option, I did various formulas. Nothing helps, as numbers are goes back as they were after file is saved. I need to save those files and also I need to use this specific format.

 

I'm out of ideas. Maybe some of you encountered similliar problem and is able to tell me what I'm doing wrong?

 

Big thanks!

2 Replies

@SAPconsultant2095 

 

Nothing is wrong, so there is nothing we can do to "correct" the "problem" -- unless you want to store the data as text.

 

For example, with the value in A1, enter =TEXT(A1,"0,000") into A2.  If you wish, copy A2 and paste-special-value into A1 to replace numeric 99999,999 (in your language) with the string "99999,999" (in any language).

 

As I imply, the problem with that work-around is that the appearance of the number is not language-dependent.  You might consider that good or bad.  For example, the numeric value 99999,999, as you see it, correctly appears as 99999.999 to me, since I use period for the decimal point, not comma as you do.  But the string "99999,999" will always appear with a comma separator.  Consequently, formulas that treat the string as a number might fail when I open the Excel file.

 

------

Explanation....

 

Contrary to most online documentation (including MSFT's), numbers are not "stored with 15 significant decimal digits of precision".

 

Instead, numbers are represented in a binary form in memory, called 64-bit binary floating-point.  And since most decimal fractions (e.g. 0.999) cannot be represented exactly in that binary form, they are approximated by the sum of 53 consecutive powers of 2.

 

The reason that we see only up to 15 significant digits in Excel is because Excel arbitrary limits the display and formatting of numbers to that many digits.

 

But in fact, the 64BFP standard states that it requires 17 significant digits, rounded, in order to convert between all decimal and binary respresentations with no loss of precision.

 

So, Excel usually writes up to 17 significant digits into XML files.

 

The exact decimal representation of the binary approximation of 99999.999 is 99999.998999999996158294379711151123046875 .  The first 15 significant digits are in red; the next 2 significant digits (for a total of 17) are in green.

 

Thus, 99999.998999999996 is the correct 17-digit approximation of the exact binary representation of 99999.999.

 

And since that is correct, there is nothing we can do about it.

 

-----

That said, Excel is peculiar about how many fractional digits it does write into XML files.

 

For example, if the numeric value is 99999.99 instead of 99999.999, we see 99999.99 in the XML file instead of 99999.990000000005, even though the exact decimal representation is 99999.990000000005238689482212066650390625 .

 

I have not (yet) intuited a rule that explains when Excel chooses to write the 15-digit vs 17-digit approximation of a binary value when the value can be approximated accurately with just 15 significant digits.  I don't know if this is specified in any of the controlling specifications and standards.

@SAPconsultant2095   PS....

 

You wrote:  ``I'm having a problem with numbers while trying to upload my .XML files to another programs``

 

Explain the problem that you are having in "other programs".

 

What are the other "programs"?  Are they actually a different application?  Or do you mean "other Excel workbooks"?

 

Is the problem that 99999.998999999996 is input as 99999.9989999999, truncating instead of rounding after 15 significant digits, as Excel does with text input?

 

If so, you might need to work around the problem one way or another.

 

But it is difficult to advise you without more details; at least the answer to my questions.

 

-----

 

You wrote:  ``If I edit file (in notepad) and remove additional digits it looks alright, but when i'm trying to save a file with new numbers (99999,999) it goes back to previous number (99999.998999999996)``

 

That description does not make sense to me.

 

If you edit the XML file using Notepad, then save as an XML file, I assure you that the saved XML file contains your edits.  Notepad does not do any conversion of the text.  Confirm by re-opening the re-saved XML file in Notepad.

 

I suspect you are omitting some steps.

 

Perhaps you open the XML file in Excel, then re-save as XML.  In that case, of course, Excel rewrites the XML contents according to its own rules, as I explained them previously.

 

But again, we cannot advise you without more (and accurate) details.