FormatNumber ( number, format )
Rate this function: Average rating: 4.2 (13 votes) Discuss this Custom Function
Lewis C. Lorenz, Lorenz Companies
www.LorenzCom.com/software
Returns text string of number in the requested format. Function allows complete FileMaker Pro number formatting using an intuitive freeform format structure.
Sample Input:
FormatNumber ( 14725.3675, “$,.2 US” )
FormatNumber ( 14725.3675, “$(,.2) US\r0\” )
FormatNumber ( 14725.3675, “#,.\c255\” )
FormatNumber ( 1, “YesNo” )
FormatNumber ( 5973600, "^" )
FormatNumber ( 59703600, "~0 kg" ) 

Sample Output:
$14,725.37 US
$(14,725.36) US [rounding off]
#14,725.3675 [text color is red]
Yes
5.9736e6
59.7036e6 kg 

Description:
FormatNumber ( number, format )
Returns a text string of the number in the requested format.
By Lewis C. Lorenz
Last updated: 2/11/2014
Function allows complete FileMaker Pro number formatting using an intuitive, liberal format structure. Freeform formatting provides the user flexible control over what is included in the final formatted result. Escaped options can be used instead. Include the following elements in the format string in the order the user desires to produce a formatted number.
HELP:
Passing '?' as the only content of 'format' returns a shortened version of this text.
NUMBER FORMATTING:
,  (thousands separator) integer portion of the number is "thousands separated".
.  (decimal separator) displays of the decimal portion of the number.
#  (number) specifies the rounding precision (controls the count of decimal number digits to display):
0  number decimal and decimal separator is not displayed. Enables positioning of negative signs and notations.
1...n  Truncation and rounding precision of the number decimal.
.  decimal separator only, with no number, displays the unaltered number decimal.
^  (caret) formats number in scientific E notation.
~  (tilde) formats number in engineering E notation.
NEGATIVE SIGN FORMATTING:
  minus sign (default) (default: left).
<>  angle brackets (default: left and rigth).
()  parentheses (default: left and right).
CR  credit symbol (default: right).
∆  delta symbol (default: left). (Black delta is output.)
Minus sign, credit and delta symbols can be displayed on the left or right of the formatted number by placing them to the left or right of an included decimal separator, or zero, in 'format'. Negative signs are placed at their default location when no decimal separator is included.
BOOLEAN FORMATTING:
  two pipe characters divide boolean results. True number returns left side. False number returns right side.
NOTATION FORMATTING:
%  percent sign. Inclusion in 'format' forces multiplication of the number by 100 (default: right).
$, £, #, etc.  dollar, pound, hash, and any other characters, can be included in the formatted number (default: left).
Percent, currency and other notations can be placed on either side of the formatted number depending on whether you place them at the left or right of an included decimal separator, or zero, in 'format'. Notations are placed at their default position when no decimal separator is included. The user must insure that the notations in 'format' produces the desired formatted result.
ESCAPED OPTIONS FORMATTING:
\T  (text) thousands separator (default: system).
\D  (text) decimal separator (default: system).
\R  (boolean) round number to passed precision (default: true).
\Z  (boolean) show number if zero (default: true).
\F  (boolean) fill (pad) decimal with zeros to length of passed precision (default: true).
\SL  (text) negative sign (, <>, (), CR, ∆) appearing on left side of number (default: minus sign).
\SR  (text) negative sign (, <>, (), CR, ∆) appearing on right side of number (default: empty).
\PL  (boolean) proximity of negative sign on left side is next to number (default: true).
\PR  (boolean) proximity of negative sign on right side is next to number (default: true).
\NL  (text) notation sign ($, %, #, etc.) to appear on left side of number (default: empty).
\NR  (text) notation sign ($, %, #, etc.) to appear on right side of number (default: empty).
\C  (integers) commaseparated RGB number text (#,#,#) to color negative number (default: black).
\X  (integer) exponentiation formatting: 0 = none, 1 = scientific, 2 = engineering (default: 0).
\BP  (text) positive response to boolean formatting.
\BN  (text) negative response to boolean formatting.
Escaped options override freeform format, defaults and add formatting. Enclose each option with escape (backslash) characters \\\\.
EXAMPLES:
FormatNumber ( 14725.3675, "$,.2 US" ) = $14,725.37 US
FormatNumber ( 14725.3675, "$(,.2) US\r0\" ) = $(14,725.36) US [rounding off]
FormatNumber ( 14725.3675, "#,.\c255\" ) = #14,725.3675 [text color is red]
FormatNumber ( 1, "YesNo" ) = Yes
FormatNumber ( 5973600, "^" ) = 5.9736e6
FormatNumber ( 59703600, "~0 kg" ) = 59.7036e6 kg
REVISION NOTES:
Revised February 11, 2014. Added code to process numbers input in scientific notation format and to return numbers in scientific and engineering notation format. Reformatted the boolean separator to be two pipe characters and added escape options to allow setting Boolean positive and negative values. Optimized the code to remove redundancies, decrease the overall size, and speed up processing. Restructured the help text to make it more concise so that it can be used easier in tool tip popups. Also, added code to determine system decimal and thousands separators.
Note: these functions are not guaranteed
or supported by BrianDunning.com. Please contact the individual
developer with any questions or problems.
This is my Custom Function and I want to
edit it
Discuss:There are no comments yet. Be the first to post a comment about this Custom Function! Please try to keep it brief & to the point. Anyone can post:

Newest Custom Functions:
1. 
FileNameFromContainer ( containerField ) 

(Thu, May 21, 11:34am) 
2. 
CF_Tooltip ( Fieldname ; ShowTooltip ) 

(Sun, May 17, 1:11am) 
3. 
ErrorDescription ( errorNumber ) 

(Tue, May 12, 3:47pm) 
4. 
Global Placeholder ( FieldName ) 

(Tue, May 12, 10:48am) 
5. 
ValuesIntersection ( ValuesListA; ValuesListB; passNullStringHere ) 

(Mon, May 11, 11:11am) 
6. 
Zodiaco ( FECHA NAM; sign ) 

(Wed, May 06, 9:19pm) 
7. 
BetweenOpenCloseTag ( Txt ; OpenTag ; CloseTag ; n ) 

(Wed, May 06, 5:47am) 
8. 
Soundex ( myfield ) 

(Sun, May 03, 12:40am) 

