在Coldfusion中等于

在Coldfusion中等于

本文介绍了字符串'00'在Coldfusion中等于'.0'吗?还有什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我注意到ColdFusion对于条件'00' == '.0'返回true.
在CF 9.1和CF 10中可以重现.
我可以通过添加find('.', foo)条件来轻松解决此问题,但这是不正常的.

So I noticed that ColdFusion returns true for the condition '00' == '.0'.
This is reproducible in CF 9.1 and CF 10.
I could easily work around this by adding a find('.', foo) condition, but this is NOT normal.

像这样的事情使我怀疑ColdFusion.这让我想知道为什么在这种明显错误的条件下它会返回true,它还认为其他什么值相等?

Things like this make me doubt ColdFusion. It makes me wonder why it returns true on this clearly false condition, and what other values would it consider equal?

是否存在无法在Coldfusion中进行比较的值列表?还是更好,是否有一个可靠的解决方案来防止这种不匹配?

Is there a list of values that you can't compare in Coldfusion? Or better yet, is there a solid solution to prevent this mismatching?

推荐答案

正如haxtb所指出的,有关此问题的更多信息,请参见:评估和类型转换问题.这是类型转换问题,ColdFusion尝试将短字符串值解释为日期时间,布尔值或数字值,而不是字符串.一些示例:

As haxtb pointed out, there is more info about this issue here: Evaluation and type conversion issues. It's a type conversion issue where ColdFusion tries to interpret the short string values as datetime, boolean or numeric values rather than strings. Some examples:

'1a'   //datetime: 1:00am
'1p'   //datetime: 1:00pm
'0.25' //datetime: a quarter of a day or 6:00am
'.0'   //boolean: false
'.0'   //numeric: 0

如John Wish所述,如果只想进行字符串比较,则应始终使用比较 CompareNoCase ()代替.

As John Wish mentioned, if you just want to do a string comparison, you should always use the Compare or CompareNoCase() functions instead.

这篇关于字符串'00'在Coldfusion中等于'.0'吗?还有什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 06:45