CFLib.org – Common Function Library Project

BracketNumberFormat(myNum)

Last updated August 26, 2002

author

Andrew Peterson

Version: 1 | Requires: CF5 | Library: StrLib

Description:
When using NumberFormat (under CF5) function, you have to supply place settings (a "9" or a "_") if you want to use brackets to display a negative number instead of a "-" (minus) sign. BracketNumberFormat uses NumberFormat in conjunction with a bit more code to provide a negative number with brackets surrounding it. In CFMX, you can simply use a number format mask of "()" to get the same result.

Return Values:
Returns a string.

Example:

<cfoutput>
#BracketNumberFormat(2109)#<br>
#BracketNumberFormat(-2109)#<br>
</cfoutput>

Parameters:

Name Description Required
myNum Number to format. Yes

Full UDF Source:

/**
 * Returns a negative number in brackets.
 * 
 * @param myNum      Number to format. (Required)
 * @return Returns a string. 
 * @author Andrew Peterson (webmaster@mail.ioc.state.il.us) 
 * @version 1, August 26, 2002 
 */
function BracketNumberFormat(myNum) {
   if(myNum eq "") {
    return 0;
    } else {
      if(myNum lt 0)
      {
         return '(' & numberformat(right(myNum, len(myNum)-1)) & ')';
      } else {
         return numberFormat(myNum);
      }
    }
  }

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