Description

Evaluates a number or Boolean value.

Returns

Yes, for a non-zero value; No for zero, false, non-Boolean values, and an empty string ("").

The function throws an exception if you pass any string other than an empty string ("").

For example, YesNoFormat("Test") throws an exception.

Category

Display and formatting functions

Syntax

YesNoFormat(value)

See also

IsBinaryIsNumeric

History

Member function added in ColdFusion (2016 release). For more information, see Member functions.

Parameters

Parameter

Description

value

A number, empty string, or a Boolean value.

Example

<cfscript>
       val1=1;
       WriteOutput(YesNoFormat(val1)); //Returns Yes
       val2=0;
       WriteOutput(YesNoFormat(val2)); //Returns No
       val3="1123";
       WriteOutput(YesNoFormat(val3)); //Returns Yes
       val4="No";
       WriteOutput(YesNoFormat(val4)); //Returns No
       val5=True;
       WriteOutput(YesNoFormat(val5)); //Returns Yes
       // try to return boolean value for non-empty string
       val6="hello";
       try{
             YesNoFormat(val6);
       }
       catch (any e){
             WriteOutput(e.message); //Displays: cannot convert the value "hello" to a boolean 
       }
</cfscript>

Using member function

<cfscript>
       val=True;
       WriteOutput(val.YesNoFormat());
</cfscript>

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy