2

我怀疑 Excel 正在计算以分数表示的重复小数的指数(例如 1/3)与没有重复小数的指数(例如 1/2)不同。它阻止了我在数字列表中找到完美立方体的公式。

A 列列出了数字 1 到 100。

B 列具有以下公式(从第 5 行开始):

=IF($A5^(1/2)-ROUND($A5^(1/2),0)=0,1,0)

如果 A 列中的数字是一个完美的正方形,例如 1、4、9 等,并且这样做正确,这应该返回“1”。我最初编写的另一个公式也适用:=IF(SQRT($A8)-ROUND(SQRT($A8),0)=0,1,0).

C 列具有以下公式(从第 5 行开始):

=IF($A5^(1/3)-ROUND($A5^(1/3),0)=0,1,0)

请注意,它与完美正方形识别公式完全相同,除了有 2 的地方是 3。对于完美立方体,如 8、27、64 等,这不会返回“1”(但确实返回“1”代表数字 1)。

谁能帮我纠正这个?

4

1 回答 1

0

I apologize for not knowing how to pick a comment as an answer, so I aggregated the helpful comments and am posting them as an answer.

Main Explanation: See Floating-point arithmetic may give inaccurate results in Excel. If you examine the underlying xml, you will see that Excel is calculating A1^(1/3) as 1.9999999999999998. The article explains why, and suggests some work arounds. – Ron Rosenfeld

Workaround I picked: Can't you replace $A5^(1/3)-ROUND($A5^(1/3) with $A5 - ROUND($A5^(1/3))^3? – r3mainer

Thanks all!

于 2020-04-04T16:10:26.383 回答