View comments | RSS feed
Contents > Developing ColdFusion MX Applications > Using ColdFusion Variables > Data type conversion > Examples of type conversion in expression evaluation PreviousNext

Examples of type conversion in expression evaluation

The following examples demonstrate ColdFusion expression evaluation.

Example 1

2 * True + "YES" - ('y' & "es")

Result value as string: "2"

Explanation: (2*True) is equal to 2; ("YES"- "yes") is equal to 0; 2 + 0 equals 2.

Example 2

True AND 2 * 3

Result value as string: "YES"

Explanation: 6 is converted to Boolean True because it is nonzero; True AND True is True.

Example 3

"Five is " & 5

Result value as string: "Five is 5"

Explanation: 5 is converted to the string "5".

Example 4

DateFormat("October 30, 2001" + 1)

Result value as string: "31-Oct-01"

Explanation: The addition operator forces the string "October 30, 2001" to be converted to a date-time object and then to a number. The number is incremented by one. The DateFormat function requires its argument to be a date-time object; thus, the result of the addition is converted to a date-time object. One is added to the date-time object, moving it ahead by one day to October 31, 2001.


Contents > Developing ColdFusion MX Applications > Using ColdFusion Variables > Data type conversion > Examples of type conversion in expression evaluation PreviousNext

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


Swathi_Sathish said on Oct 20, 2004 at 5:08 PM :
Upon experimentation I have found that in example 2 where it says TRUE AND 2*3 will return a value of YES. But it actually returns a value of 6. Although 6 is equivalent to Yes in the boolean representation, The expression result specified in the document is wrong.

Similarly TRUE and "TEST" will return TEST. Effectively when evaluating expressions involving boolean AND operators, CF checks if the value of the right hand operation is a Boolean value equivalent( such as TRUE/FALSE/YES/NO). If it is not then the value returned will be the value of the right hand operand of the AND operator if the Left hand operand evaluates to TRUE. If the Left hand Operand evaluates to False CF will not bother about the right hand operand and evaluates the result of the expression as FALSE.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/variab33.htm