SiteKickr Web Development

Accept fractions in place of numeric input

If there's one thing your competitor probably isn't doing, when it comes to online tools, it's accepting fractions for numeric input.

For instance, if you have a tool that calculates the square footage of a room, why not allow the user to enter:

Width:  5 3/4
Length: -2 3/8

Using ColdFusion for our example, by running your fields through a loop and detecting the presence of a "/" in the input, we can convert the value to a decimal number for use in our processing script:

<cfloop collection="#url#" item="key">
    <cfif Find("/", url[key])>
        <cfset url[key] = trim(url[key])>
        <cfset frac = ListLast(url[key], " ")>
        <cfif frac eq url[key]><cfset url[key] = 0></cfif>
        <cfif Left(url[key], 1) neq "-">
            <cfset url[key] = Val(url[key]) + Evaluate(frac)>
        <cfelse>
            <cfset url[key] = Val(url[key]) - Evaluate(frac)>
        </cfif>
    </cfif>
</cfloop>