CFLib.org – Common Function Library Project

BracketNumberFormat(myNum)

Last updated August 26, 2002
Download UDF

author

Andrew Peterson                                   Andrew Peterson

Version: 1 | Requires: ColdFusion 5 | Library: StrLib

 
Rated 0 time(s). Average Rating: 0

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:

<cfscript>
/**
* 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);
}
}
}
</cfscript>

Search CFLib.org


Latest Additions

Ryan Thompson-Jewell Ryan Thompson-Jewell added
ListSplit
3 day(s) ago

Nathan Dintenfass Nathan Dintenfass added
RowsToColumns
3 day(s) ago

Barney Boisvert Barney Boisvert added
indentXml
4 day(s) ago

Barney Boisvert Barney Boisvert added
REReplaceCallbac...
4 day(s) ago

Top Rated

Rob Brooks-Bilson                                 FolderSize
Rated 5.0, 7 time(s)

Nick Giovanni                                     UniqueValueList
Rated 5.0, 5 time(s)

James Sleeman                                     QuickSort
Rated 5.0, 3 time(s)

Jeff Howden ListDeleteDuplic...
Rated 5.0, 3 time(s)

Created by Raymond Camden / Design by Justin Johnson