本文介绍了为什么Excel(xlsx)将某些值和其他值保存在xml中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在解析xlsx文件,遇到了这种行为。我不知道如何在不描述重现该问题的步骤的情况下进行解释。

I am working with parsing xlsx files and came across this behaviour. I don't know how to explain it without describing the steps to reproduce the issue.

 1.  Create new blank Excel file (xlsx)
 2.  Type '8.8' into cell A1
 3.  Save file
 4.  Close Excel, rename file with .zip extension and open
 5.  Find sheet1.xml and open
 6.  Value for 8.8 in A1 will be saved as '8.8000000000000007'

此对我来说是一个问题,因为当我解析Excel文件时,我想输入的值是'8.8'而不是'8.8000000000000007'。

This creates a problem for me, because when I parse Excel files, I want to get the value typed in, '8.8' not '8.8000000000000007'.

有人知道为什么要使用Excel吗?

Does anyone know why Excel does this?

编辑:Excel如何知道当我打开该文件时只显示 8.8而不显示 8.8000000000000007? Excel是否会在特定的小数点后舍入?

And how does Excel know when I open that file to only display '8.8' and not '8.8000000000000007'? Does Excel round at a specific decimal place?

推荐答案

具有有限小数表示形式的浮点数不一定具有有限的二进制表示形式。

A floating point number which has a finite decimal representation doesn't necessarily have a finite binary representation. The conversion is a lossy one.

因为8.8是其分母(5)的幂不是2的分数,所以二进制浮点表示是无穷大的。应用程序用于存储它的基础数据类型(在本例中为Excel)具有有限的精度,因此表示被截断了。

Because 8.8 is a fraction whose denominator (5) isn't a power of 2, its binary floating-point representation is infinite. The underlying data type the application uses to store it (Excel in this case) is of finite precision, and the representation is thus truncated.

这篇关于为什么Excel(xlsx)将某些值和其他值保存在xml中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 11:54