使用C#从excel读取大于12位数字的数字时,数字被转换为零 [英] while reading number greater than 12 digits from excel using c#,number get converted to zero
问题描述
我正在尝试使用c#使用以下查询从Excel文件中读取长度大于12位的数字
i'm trying to read a number with length greater than 12 digits from excel file using c# using below query
"select Format([F1], 'Number') as Code";
但是我只能正确输入12位数字,其余的数字都转换为零.为什么呢?
But i get only 12 digits correctly and the rest of the numbers are converted into zeroes.Why is it so??
示例:787767786546347
从excel文件读取时,我得到的是787767786546000
Example : 787767786546347
when read from excel file what i get is 787767786546000
推荐答案
根据MSDN:
Excel在如何存储和计算浮点数方面遵循IEEE 754规范.因此,Excel在一个数字中仅存储15位有效数字,并将第15位后的数字更改为零.
Excel follows the IEEE 754 specification on how to store and calculate floating-point numbers. Excel therefore stores only 15 significant digits in a number, and changes digits after the fifteenth place to zeroes.
要变通解决此问题,将单元格设置为文本格式.然后该单元格最多可以显示1,024个字符.
To work around this behavior, format the cell as text. The cell can then display up to 1,024 characters.
http://support.microsoft.com/kb/269370
这篇关于使用C#从excel读取大于12位数字的数字时,数字被转换为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!