Migration Solutions for ColdFusion Applications to ASP.NET
      
New Atlanta Product Forums Profile | Search | Login | RSS
New Topic Reply   Previous Page  Page: 1   Next Page

Thread: Unexpected result for EQ when 2 decimal points in string
Created on: 08/01/12 09:21 AM Replies: 1
Peter


Joined: 03/31/08
Posts: 22
Unexpected result for EQ when 2 decimal points in string
08/01/12 9:21 AM

I am using BlueDragon Server JX/7.1.1.39 and if (for example) I run the following code

<cfoutput>

<cfset X = "1.6.02">

<cfset Y = "1.6.2">

X = #X#<br>

Y = #Y#<br>

<cfif X eq Y>

   Test 1 - X is equal to Y

<cfelse>

   Test 1 - X is not equal to Y

</cfif>

<br>

<cfif CompareNoCase(X,Y) eq 0>

   Test 2 - X is equal to Y

<cfelse>

   Test 2 - X is not equal to Y

</cfif>

</cfoutput>


I will get the following result
X = 1.6.02
Y = 1.6.2
Test 1 - X is equal to Y
Test 2 - X is not equal to Y

This seems to only happen when all characters are numeric and there are 2 decimal points.

Why?
Link | Top | Bottom
Peter


Joined: 03/31/08
Posts: 22
RE: Unexpected result for EQ when 2 decimal points in string
04/15/16 9:57 PM

It’s been a long time since I first posted this but in case anyone wants to know why the two values are considered equivalent, it is because 1.6.2 and 1.6.02 are both being interpreted as dates and therefore are equal. If the values were “40.6.2” and “40.6.02” then they could not be considered as valid dates and are then compared as string values. This automatic conversion of data types can be a trap. For example “0800” and 800 are also treated as equal values because any string that can be converted to a numeric value is automatically converted. There is an article about this behaviour at https://helpx.adobe.com/coldfusion/developing-applications/the-cfml-programming-language/using-coldfusion-variables/data-type-conversion.html
Link | Top | Bottom

New Post
Please login to post a response.


company media information terms of use privacy policy contact us
This page was dynamically built on the BlueDragon CFML Engine