Creates a custom-formatted number value. For international
number formatting use LSNumberFormat.
The mask is made up of:
_,9 Digit placeholder; . decimal point; 0 Pads with zeros;
( ) less than zero, puts parentheses around the mask
+ plus sign before positive number minus before negative
- a space before positive minus sign before negative
, Separates every third decimal place with a comma.
L,C Left-justifies or center-justifies number
$ dollar sign before formatted number.
^ Separates left and right formatting.
numberFormat(number [, mask])
→ returns string
<cfoutput>1.234 ('__.00') -> #numberFormat(1.234,'__.00')#<br/> <!--- 1.23 --->
1234 ('__.00') -> #numberFormat(1234,'__.00')#<br/> <!--- 1234.00 ---></cfoutput>
<cfoutput>
123 ('00000') -> #numberFormat(123,'00000')#<br/>
123 ('99999') -> #numberFormat(123,'99999')#<br/>
123 ('99.99999') -> #numberFormat(123.12,'99.99999')#<br/>
</cfoutput>
<cfoutput>
123 ('_____') -> #numberFormat(123,'_____')#<br/>
123 ('_.___') -> #numberFormat(123,'_.___')#<br/>
11.10 ('__.000') -> #numberFormat(11.10,'__.000')#<br/>
</cfoutput>
<cfoutput>
123 ('+') -> #numberFormat(123,'+')#<br/>
-123 ('-') -> #numberFormat(-123,'-')#<br/>
</cfoutput>
<cfoutput>
123 (',') -> #numberFormat(123,',')#<br/>
123456 (',') -> #numberFormat(123456,',')#<br/>
</cfoutput>
<cfoutput>
1 ("L999") -> #NumberFormat( 1, "L999" )#<br/>
1 ("C000") -> #NumberFormat( 1, "C000" )#<br/>
</cfoutput>
numberFormat(1.23,'__.00')
Expected Result: 1.23
numberFormat(123,'__.00')
Expected Result: 123.00
num1 = NumberFormat(123,'00000');
num2 = NumberFormat(123,'99999');
writeOutput(num1&'/'&num2);
Expected Result: 00123/ 123
num1 = NumberFormat( 5, "+" );
num2 = NumberFormat( -5, "+" );
writeOutput(num1&'/'&num2);
Expected Result: +5/-5
You could use dollarFormat() or lsCurrencyFormat() instead
numberFormat(123456789,'_$,9.99')
Expected Result: $123,456,789.00
Signup for cfbreak
to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.