Simple HLOOKUP Failing with Excel 2010

a 夏天 提交于 2019-12-23 18:20:16

问题


I have an Excel spreadsheet (generated by spreadsheet gear, but it's more an Excel problem) that isn't functioning as i would expect when I use HLOOKUPS. I use a simple HLOOKUP to look up the value at a given percent in a table. For two certain values, the HLOOKUP fails. These values are 0.9993 and 0.999. This excel document demonstrates the problem: http://dsokol.com/tokio/excelna.xlsx. Cells C6 and C7 are showing as N/A, when they are intended to be populated with B and C. If I re-key over the values, the HLOOKUPs start working again.

Can anyone explain why this is occurring?


回答1:


I agree with Barry. This problem is not related to whether or not they are numbers or strings(they are all numbers). This appears to be a limitation of storing floating point numbers in binary - as described here: http://support.microsoft.com/kb/214118

Many combinations of arithmetic operations on floating-point numbers in Microsoft Excel and Microsoft Works may produce results that appear to be incorrect by very small amounts. For example, the equation =1*(.5-.4-.1) may be evaluated to the quantity (-2.78E-17), or -0.0000000000000000278 instead of 0.

This problem is not unique to excel either but rather a result of:

IEEE 754 specifies that numbers be stored in binary format to reduce storage requirements and allow the built-in binary arithmetic instructions that are available on all microprocessors to process the data in a relatively rapid fashion. However, some numbers that are simple, nonrepeating decimal numbers are converted into repeating binary numbers that cannot be stored with perfect accuracy.

This phenomenon is visible here in "Arithmetic Equality":

Again this is not a problem that is unique to excel:

This behavior is not a problem in or a limitation of Excel or Works; this behavior occurs because the Institute of Electrical and Electronics Engineers (IEEE) 754 floating-point standard requires that numbers be stored in binary format.

Good Luck.




回答2:


The problem is those numbers are being stored as strings and not integers. I guess you need to explicitly declare the column type in SpreadSheet Gear.

If you open the xlsx file as a zip file, and extract Sheet1.xml from the xl\WorkSheets folder before and after overwriting the values, any diff tool (e.g. winmerge makes this obvious).

I have posted the XML differences on this gist.



来源:https://stackoverflow.com/questions/12695417/simple-hlookup-failing-with-excel-2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!