CFLib.org – Common Function Library Project

booleanize([value])

Last updated July 3, 2006

Version: 1 | Requires: ColdFusion MX7 | Library: DataManipulationLib

 
Rated 1 time(s). Average Rating: 5.0

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:

view plain print about
<cfset one = "true">
<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:

view plain print about
<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>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
10 day(s) ago

Will Belden Will Belden added
longTime
15 day(s) ago

James Sleeman James Sleeman added
quickSort
25 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
28 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson