Possible comparison bug
hi all,
there's one, may have obvious answer (and that's reason first decided ask here before filing bug).
<cfset t1 = tostring("00237000000075384887")>
<cfset t2 = tostring("00237000000075384892")>
<cfif t1 eq t2><cfoutput>#t1# equal #t2#</cfoutput><cfelse><cfoutput>#t1# different #t2#</cfoutput></cfif>
the result of above rather surprising. sort of comparison thinks numbers equal. also, if both numbers converted strings, coldfusion still thinks equal.
if using compare(t1,t2) however, coldfusion starts comparing strings us, humans , distinguishes difference between them
now if there's known limitation comparing long numbers etc. or fact middle of each of them filled zeros affects all, welcome point out me.
simon
do google on "floating point precision".
as cf loosely typed, has make guesses when comes doing operations in type significant. eq operator example of this: if cf can cast operands numerics, will, it's doing here. , when casts strings numerics, both 2.37000000075e+017, equal.
if want compare 2 strings explicitly strings, need use compare(), ahve surmised.
there no surprises in you're seeing though.
--
adam
More discussions in ColdFusion
adobe
Comments
Post a Comment