Comparison of strings
Hello,
I have a problem with the comparison of strings:
If I compare the values 0,5 and 5,0 I will get the result that the values are equal (Case 1).
If I compare the values 0.5 and 5.0 the comparison will be correct (Case 2).
If I compare the values with the method 'compare()' the comparison is correct (Case 3).
Why is the result of case 1 wrong? Is there an explanation or is this a bug?
<cfscript>
// wrong comparsion
writeoutput("Case 1: comparsion with 'if' and '==' <br>");
string_one = "0,5";
string_two = "5,0";
writeoutput("values: <font color=green>String one: #String_one#</font> - <font color=red> String Two: #string_two#</font><br><br>");
if (string_one == string_two) {
writeoutput("wrong result after the comparsion: #string_one# is not #string_two#<br><br>");
}
else {
writeoutput("right result after the comparsion: #string_one# is not #string_two#<br><br>");
}
writeoutput("===============================<br>");
// right comparsion
writeoutput("Case 2: comparsion with 'if' and '==' <br>");
string_three = "0.5";
string_four = "5.0";
writeoutput("values: <font color=green>String three: #String_three#</font> - <font color=red> String four: #string_four#</font><br><br>");
if (string_three == string_four) {
writeoutput("wrong result after the comparsion: #string_three# is not #string_four#<br><br>");
}
else {
writeoutput("right result after the comparsion: #string_three# is not #string_four#<br><br>");
}
writeoutput("===============================<br>");
// right comparsion
writeoutput("Case 3: comparsion with 'compare' <br>");
string_five = "0,5";
string_six = "5,0";
writeoutput("values: <font color=green>String five: #String_five#</font> - <font color=red> String six: #string_six#</font><br><br>");
if (compare(string_five,string_six) EQ 0){
writeoutput("wrong result after the comparsion: #string_five# is not #string_six#<br><br>");
}
else{
writeoutput("right result after the comparsion: #string_five# is not #string_six#<br><br>");
}
writeoutput("===============================<br>");
writeoutput('</strong>');
</cfscript>
