2

我在 Windows 7 64 上使用 MSAccess 2010。

我正在比较查询中的两个表。我正在加入一个复合 PK 并选择表 A 列 A <> 表 B 列 A 的行,其中两个表的 A 列都是双精度的。

它适用于 120 行。对于 28 行,表 A 列 A 中的值 0.088 <> 表 B 列 A 中的 0.088。

任何地方都没有使用文本函数。

当我向查询 a:[TableA]![ColumnA] - [TableB]![ColumnA] 添加一列时,我返回的值类似于 -1.38777878078145E-17。

当我将查询导出到 Excel 并进行数学运算时,结果 = 0。

0.088 - 0.088 <> 0 怎么可能?0.088 double <> 0.088 double 怎么可能?

4

1 回答 1

1

This is a very common problem related to the nature of floating-point numbers in any computing context (not just Access). It seems like a paradox, but the fact is that a Double value can approximately represent a huge range of numbers very precisely (up to 15 significant digits, ref: here), but that representation is almost never exact. That's why:

  • exact comparisons of floating numbers (e.g. x=y) can sometimes fail, and therefore

  • you should never rely on a JOIN between two Double fields.

More information on floating-point numbers is available here. Wikipedia also addresses the issue here.

If you have fields with decimal places that require exact comparisons then you may want to consider changing them to Currency or Decimal.

于 2013-05-31T08:58:14.113 回答