Evaluates a number or Boolean value.
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.
Display and formatting functions
YesNoFormat(value) |
Member function added in ColdFusion (2016 release). For more information, see Member functions.
Parameter |
Description |
|---|---|
value |
A number, empty string, or a Boolean value. |
<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>
<cfscript>
val=True;
WriteOutput(val.YesNoFormat());
</cfscript>
Sign in to your account