Hidden Special Characters in Variable
I am having a weird issue and for the life of me cannot figure out the root cause. I have a query that is pulling back some data including a summed money data type from sqlserver called totalAmount. We are looping over these rows and adding up some totals of the rows such as:
<cfset myAA = 0 />
<cfset myAB = 0 />
<cfloop ... >
<cfif ... >
<cfset myAA = myAA + getPayments.totalAmount />
<cfelse>
<cfset myAB = myAB+ getPayments.totalAmount />
</cfif>
</cfloop>
At this point we add the 2 together...
<cfset mySum = myAA + myAB />
We are expecting this to be 0, but in one instance it is not so, even though it should be.
Outputting the two variables gives them as -75.03 and 75.03. When these are added together the result is:
-1.05160324892E-012
If I do a trim like:
<cfset mySum = trim(myAA) + trim(myAB) />
It returns 0. So it seems there is an additional character on one or both of those variables, but what is it and where is it coming from? If I output:
(#myAA#) + (#myAB#)
I get (-75.03) + (75.03). So no whitespace... If I do a len() on each I get 6 and 5.
If I do a compare such as #myAA# => #(myAA eq "-75.03")#
I get -75.03 => NO, same with the other.
So I am dumbfounded, it seems there is a control character there that is hidden and throwing this off. Anyone have any suggestions on what to check or any ideas what the problem may be? I would rather fix the problem at the root rather than throwing trim() around variables that should be numeric to begin with.
-Shawn
