ObjectScript Reference
$FNUMBER


$FNUMBER(inumber,format,decimal) $FN(inumber,format,decimal)
inumber  The number to be formatted. It can be a numeric literal, a variable, or any valid ObjectScript expression that evaluates to a numeric value. 
format  Optional — Specifies how the number is to be formatted. Specified as a quoted string consisting of zero or more format codes, in any order. Format codes are described below. Note that some format codes are incompatible and result in an error. For default formatting, with or without the decimal parameter, you can specify the empty string (""). If omitted, defaults to the empty string (""). 
decimal  Optional — The number of fractional decimal digits to be included in the returned number. If format is omitted, include a placeholder comma before specifying decimal. 
Code  Description 

""  Empty string. Returns inumber in canonical number format. This format is the same as "L" format. 
+  Returns a nonnegative number prefixed by the PlusSign property of the current locale (“+” by default). If the number is negative, it returns the number prefixed by the MinusSign property of the current locale (“” by default). 
  Returns the absolute value of a number. Always returns a negative number without the MinusSign character. Returns a positive number without the PlusSign character. When combined with the “+” format code ("+", returns positive numbers with a plus sign, negative numbers with no sign. This code cannot be used with the “P” format code; attempting to do so results in a <SYNTAX> error. 
,  Returns the number with the value of the NumericGroupSeparator property of the current locale inserted every NumericGroupSize numerals to the left of the decimal point. Combining “,” with either “.” or “N” formats results in a <FUNCTION> error. 
.  Returns the number using standard European formatting, regardless of the current locale settings. Sets DecimalSeparator to comma (,), NumericGroupSeparator to period (.), NumericGroupSize to 3, PlusSign to plus (+), MinusSign to minus (). Combining “.” with either “,” or “O” formats results in a <FUNCTION> error. 
D  $DOUBLE special formatting. This code has two effects: “D” specifies that $DOUBLE(0) should return 0; otherwise, $DOUBLE(0) returns 0. However, “D” overrides the negative sign and returns 0. You can specify “D” or “d” for this code; a returned INF or NAN will be expressed in the corresponding uppercase or lowercase letters. The default is upper case. 
E  Enotation (scientific notation). Returns the number in scientific notation. If you omit the decimal number of fractional digits, 6 is used as the default. You can specify “E” or “e” for this code; the returned value will contain the corresponding uppercase or lowercase symbol. The exponent portion of the returned value is two digits in length with a leading sign, unless three exponent digits are required. “E” and “G” are incompatible and result in a <FUNCTION> error. 
G  Enotation or fixed decimal notation. If the number of fractional digits that would result from conversion to scientific notation is larger than the decimal value (or the default of 6 decimal digits), the number is returned in scientific notation. For example, $FNUMBER(1234.99,"G",2) returns 1.23E+03. If the number of fractional digits that would result from conversion to scientific notation is equal to or smaller than the decimal value (or the default of 6 decimal digits), the number is returned in fixed decimal (standard) notation. For example, $FNUMBER(1234.99,"G",3) returns 1235. You can specify “G” or “g” for this code; the returned scientific notation value will contain the corresponding uppercase “E” or lowercase “e”. “E” and “G” are incompatible and result in a <FUNCTION> error. 
L  Leading sign. Sign, if present, must precede the numerical portion of inumber. Parentheses are not permitted. This code cannot be used with the “P” or “T” format codes; attempting to do so results in a <SYNTAX> or <FUNCTION> error. Leading sign is the default format. 
N  No NumericGroupSeparator. Does not allow the use of a numeric group separator. This format code is incompatible with the comma (,) format code. When used with the dot format code ("N.") the number is formatted with the European decimal separator but no numeric group separators. 
O  ODBC locale. Overrides the current locale, and instead uses the standard ODBC locale with the following values: PlusSign=+; MinusSign=; DecimalSeparator=.; NumericGroupSeparator=,; NumericGroupSize=3. By itself, the “O” format code uses only the ODBC MinusSign and DecimalSeparator. This format code is incompatible with the dot (.) format code. When used with the comma format code ("O,") the number is formatted with the ODBC decimal separator and ODBC numeric group separators. 
P  Parentheses sign. Returns a negative number in parentheses and without a leading MinusSign locale property value. Otherwise, it returns the number without parentheses, but with a leading and trailing space character. This code cannot be used with the “+”, “”, “L”, or “T” format codes; attempting to do so results in a <SYNTAX> error. 
T  Trailing sign. Returns the number with a trailing sign if a prefix sign would otherwise have been generated. However, it does not force a trailing sign. To produce a trailing sign for a nonnegative number (positive or zero), you must also specify the “+” format code. To produce a trailing sign for a negative number, you must not specify the “” format code. The trailing sign used is determined by the PlusSign and MinusSign properties of the current locale respectively. A trailing space character, but no sign, is inserted in the case of a nonnegative number with “+” omitted or in the case of a negative number with “” specified. Parentheses are not permitted. This code cannot be used with the “L” or “P” format codes; attempting to do so results in a <SYNTAX> or <FUNCTION> error. 
SET c="6.25198" SET x=$FNUMBER(c,"+",3) SET y=$FNUMBER(c,"+",8) WRITE !,x,!,y
SET a=1234 WRITE $FNUMBER(a),! ; returns 1234 WRITE $FNUMBER(a,""),! ; returns 1234 WRITE $FNUMBER(a,"+"),! ; returns +1234 WRITE $FNUMBER(a,""),! ; returns 1234 WRITE $FNUMBER(a,"L"),! ; returns 1234 WRITE $FNUMBER(a,"T"),! ; returns 1234 (with a trailing space) WRITE $FNUMBER(a,"T+"),! ; returns 1234+
SET b=1234 WRITE $FNUMBER(b,""),! ; returns 1234 WRITE $FNUMBER(b,"+"),! ; returns 1234 WRITE $FNUMBER(b,""),! ; returns 1234 WRITE $FNUMBER(b,"L"),! ; returns 1234 WRITE $FNUMBER(b,"T"),! ; returns 1234
WRITE "*",$FNUMBER(123,"P"),"*",! ; returns *(123)* WRITE "*",$FNUMBER(123,"P"),"*",! ; returns * 123 *
SET x=1234567.81 WRITE $FNUMBER(x,",")
SET x=1234567.81 WRITE $FNUMBER(x,".")
SET x=124329 WRITE $FNUMBER(x,",",2)
SET x=124329 WRITE $FNUMBER(x,,2)
SET x=.7799 WRITE $FNUMBER(x,,2)
WRITE ##class(%SYS.NLS.Format).GetFormatItem("DecimalSeparator")
WRITE ##class(%SYS.NLS.Format).GetFormatItem("NumericGroupSeparator"),! WRITE ##class(%SYS.NLS.Format).GetFormatItem("NumericGroupSize")
WRITE ##class(%SYS.NLS.Format).GetFormatItem("PlusSign"),! WRITE ##class(%SYS.NLS.Format).GetFormatItem("MinusSign")