简体   繁体   中英

openxml and Excel 15 digits number limit

I am using POI from apache to read from an Excel file in a java program. The excel has macros that I have reproduced in Java but when I compare the results, there are small rounding differences that I am trying to eradicate as much as possible. After downloading the code of POI 3.13 and running it in debug mode I realized that they are not handling numbers like Excel, which is using only 15 digits and adding non-significant 0s after, but instead using a representation on 17 digits. You can see that here . But going deeper, it seems that POI is using openxml and that openxml Cell already store the floating point numbers on 17 digits instead of 15... So it seems to me that there is a bug in handling number in openxml but I am quite surprised that something that "big" as badly handling floating point numbers hasn't been spotted before as I can't find anything about that.

So my question : is there a workaround to get the exact same 15 digits of Excel when using POI? And better, can openxml be corrected to act like Excel on this matter?

but I am quite surprised that something that "big" as badly handling floating point numbers hasn't been spotted before

Excel's use of floating-point is misguided, as well-documented in §2 of this article . Microsoft's poor attempt to pretend that values are 15-digit decimal floating-point when they are really 53-digit binary floating-point only makes things worse, and rather than emulating it, you should avoid using Excel for serious computations. Here is a quote from the conclusion of §2:

How can a user of Excel predict which functions act upon displayed instead of actual values? Which expressions get rounded cosmetically before being displayed? The user's program cannot be debugged without an awareness of these questions, and an aware user ends up debugging Microsoft's pious fraud instead of just a malfunctioning Excel spreadsheet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM