This is why I hate coldfusion. It doesn't hold to any conventions about
how objects should be compared. For example, strings of different
lengths get evaluated completely differently. I know of no other
language that does this.
<cfscript>
a = '12345';
b = '12346';
// Should be false, and is false.
writeoutput('#a# eq #b# == #a eq b#<br />');
a = '2707200116272368271111';
b = '2707200116272368279465';
// Should be false, but isn't.
writeoutput('#a# eq #b# == #a eq b#<br />');
</cfscript>
And I thought, "Nah, that's just with adobe's". Wrong. Railo's output:
12345 eq 12346 == false
2707200116272368271111 eq 2707200116272368279465 == true
<cfscript>
a = 'xyz2707200116272368271111';
b = 'xyz2707200116272368279465';
// can't be converted to numbers
writeoutput('#a# eq #b# == #a eq b#<br />');
</cfscript>
gives:
xyz270720011627236821111 eq xyz270720011627236829465 == false
As an aside,
<cfswitch expression="#a#">
<cfcase value="270720011627236829465">
<cfoutput>270720011627236829465</cfoutput>
</cfcase>
<cfcase value="270720011627236821111">
<cfoutput>270720011627236821111</cfoutput>
</cfcase>
</cfswitch>
gives what you'd want with Railo:
270720011627236821111
with adobe cf:
Context validation error for the cfcase tag.
The cfswitch tag has a duplicate cfcase tag for value
2.7072001162723682E20.
Ryan,
It appears that you are ok if the data between quotes is interpreted as a string instead of as a number.
so this would be a number "1234567890123456789"
but "1234-5678901-23456789" would be a string.
Andrew Penhorwood
<cfoutput>#Compare(a,b)#<br></cfoutput>
returns:
-1
<cfset a = 270720011627236821111>
<cfset b = 270720011627236829465>
<cfoutput>#Compare(a,b)#<br></cfoutput>
<cfoutput>#Compare("#a#","#b#")#<br></cfoutput>
returns:
0
0
Michael Offner-Streit escreveu:
> the problem is and yes it is a problem, in java numbers are restricted
> in (byte) size.
> Railo use internally double values for all number operations.
> it is possible to use BigDecimal but this is very slow.
>
What about using BigDecimal only for values greater than <Doble_Limit>?
Example: the same way you check it "01" should be compared either as a
string or as a number, you can check it can be compared either as a
double or as a bigdecimal.
Ronan