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);
      }
    }
  }
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson