forceBoolean(bool)
Last updated September 5, 2010
Version: 1 | Requires: ColdFusion 5 | 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:
<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:
<cfscript>
/**
* 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";
}
</cfscript>
Search CFLib.org
Latest Additions
Tayo Akinmade added
arrayTrim
3 day(s) ago
Will Belden added
longTime
9 day(s) ago
James Sleeman added
quickSort
19 day(s) ago
Ben Forta added
GetHostAddress
22 day(s) ago
Top Rated
EksporSQLData
Rated 5.0, 16 time(s)
backupDatabase
Rated 5.0, 13 time(s)
indentXml
Rated 5.0, 10 time(s)
generateSsccAsn
Rated 5.0, 4 time(s)