forceBoolean(bool)
Last updated September 05, 2010
Version: 1 | Requires: CF5 | Library: UtilityLib
Description:
You pass in a variable, and I will return either a "1" if it evaluates to true, or a "0" if it is not a boolean (as in an empty string or any other non-boolean) or evaluates to false.
Return Values:
Returns a boolean.
Example:
<cfset i="">
<cfif i></cfif> returns error.
<ciff forceBoolean(i)></cfif> works.
#forceBoolean(i)# returns "0".
Parameters:
Name | Description | Required |
---|---|---|
bool | Value to check. | Yes |
Full UDF Source:
/**
* Returns a boolean 1/0 from anything, including empty strings.
*
* @param bool Value to check. (Required)
* @return Returns a boolean.
* @author Alan McCollough (amccollough@anthc.org)
* @version 1, September 5, 2010
*/
function forceBoolean(bool){
if(isBoolean(bool) AND bool IS TRUE)
return "1";
else
return "0";
}
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016