String '00' equals '.0' in Coldfusion ? What else?

雨燕双飞 提交于 2019-12-24 00:37:56

问题


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.

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?

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?


回答1:


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

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



来源:https://stackoverflow.com/questions/38147638/string-00-equals-0-in-coldfusion-what-else

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