简体   繁体   English

Google表格的条件格式设置结果不正确

[英]Google Sheets incorrect conditional formatting result

this is not really programmatical question but I have no idea where else to ask. 这不是真正的程序性问题,但我不知道还有什么要问的。

在此处输入图片说明

As what screenshot shows, my conditional formatting is set to > 0 red, == 0 green, but there's just this one cell which stucks at red, anyone have any idea why? 如屏幕快照所示,我的条件格式设置为> 0红色,== 0绿色,但是只有一个单元格卡在红色上,有人知道为什么吗?

Thank you. 谢谢。

As I said in my first comment above the problem is precision. 正如我在上面的第一句话中所述,问题是精度。 Take a look at this with your sheet when formatted to display 16 decimal places. 格式化为显示小数点后16位时,请与您的工作表一起看看。

在此处输入图片说明

The offending cell which should be 0.00 is in fact 0.0000000000000071054 , and the format formula is correct to colour it red! 实际上应该为0.00有问题的单元格为0.0000000000000071054 ,并且格式公式正确地将其着色为红色!

Why? 为什么? In general when using floating point numbers the precision is limited based on the internal length of the numbers being stored with 64 bit being common. 通常,当使用浮点数时,精度会受到所存储数字内部长度的限制,通常以64位为准。 So they are not exact. 因此它们并不精确。

This means its hazardous to do do exact comparisons on floating point numbers. 这意味着对浮点数进行精确比较非常危险。 The results can be surprising as your example shows, if you don't understand how floats behave. 如您的示例所示,如果您不了解浮点数的行为,结果可能会令人惊讶。 You can search on line for more details. 您可以在线搜索更多详细信息。 The crux of the matter is that you need to test if the difference is greater or less than some small number - like 0.0000001 for example. 问题的关键是您需要测试差异是否大于或小于某个较小的数字,例如0.0000001。 A workable test for "equality" would be abs(ab) < 0.00000001 . 一个可行的“平等”测试将是abs(ab) < 0.00000001

Workaround: The simplest in your case would be to replace the formulas in column K with round(H23-J23,8) for row 23 for example. 解决方法:最简单的情况是将第23行的K列公式替换为round(H23-J23,8) Then your conditional formula will work fine in all cases. 这样,您的条件公式将在所有情况下均能正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM