CFLib.org – Common Function Library Project

verityPercentage(num)

Last updated May 09, 2003

author

Howard Owens

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Takes a verity "score" value and returns a formatted percentage. When verity returns a score, it usually looks like 0.87454, which is not an intuitive number for site browser to discern. This UDF formats the SCORE into something 88%, which is easier to read.

Return Values:
Returns a string.

Example:

<cfset score="0.87899">

<CFOUTPUT>
#verityPercentage(score)#
</CFOUTPUT>

Parameters:

Name Description Required
num Verity score. Yes

Full UDF Source:

/**
 * Takes a verity &quot;score&quot; value and returns a formatted percentage.
 * 
 * @param num      Verity score. (Required)
 * @return Returns a string. 
 * @author Howard Owens (howens@insidevc.com) 
 * @version 1, August 10, 2003 
 */
function verityPercentage(num){
    var outNum = '';
    var leftDigit=ListFirst(num, '.');
    var rightDigits=Left(ListGetAt(num, 2, '.'), 2);
    
    if (right(rightDigits, 2) GTE 5) rightDigits = rightDigits+1;

    if (leftDigit gte 1) outNum='100' & '%';
    else outNum=RightDigits & '%';
    
    return outNum;
}

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

Created by Raymond Camden / Design by Justin Johnson