booleanize([value])
Last updated July 3, 2006
Version: 1 | Requires: ColdFusion MX7 | Library: DataManipulationLib
Description:
This was to help deal with a problem of access/sql conversion and there were some yes/no values that did not match to boolean values. So had to create a script to simplify universal conversion to boolean values.
Return Values:
Returns 1 or 0.
Example:
<cfset two = "0">
<cfset new_one = 0>
<cfset new_two = 0>
<b>default values:</b><br>
<cfoutput>
one = #one#<br>
two = #two#<br>
</cfoutput>
<cfoutput>
<b>New Values:</b><br>
one = #booleanize(one)#<br>
two = #booleanize(two)#<br>
</cfoutput>
Parameters:
| Name | Description | Required |
|---|---|---|
| value | The value to convert. | No |
Full UDF Source:
<cfscript>
/**
* Simply converts access yes/no or other boolean variables to 0/1 format, almost opposite of yesnoformat
*
* @param value The value to convert. (Optional)
* @return Returns 1 or 0.
* @author Craig M. Rosenblum (crosenblum@gmail.com)
* @version 1, July 3, 2006
*/
function booleanize(value) {
if (not isboolean(value)) {
value = replacenocase(value,'on',1);
value = replacenocase(value,'off',0);
}
if (yesnoformat(value) eq 'Yes') value = 1;
if (yesnoformat(value) eq 'No') value = 0;
return value;
}
</cfscript>
Search CFLib.org
Latest Additions
Tayo Akinmade added
arrayTrim
10 day(s) ago
Will Belden added
longTime
15 day(s) ago
James Sleeman added
quickSort
25 day(s) ago
Ben Forta added
GetHostAddress
28 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)