问题
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