Skip to main content
Previous section   Next section

FMTS

Formats each element of a dynamic array for display.

Synopsis

FMTS(dynarray,format)

Arguments

dynarray An expression that resolves to a dynamic array to be formatted for display.
format An expression that resolves to a string consisting of positional letter and number codes specifying the display format for the elements of dynarray.

Description

The FMTS function returns the dynarray value with each element formatted as specified by format. This formatting may include justification, character filling, and the rounding or zero padding of numeric element values. The most common use for FMTS is to provide a uniform display format for fractional numbers.

The format string has the following format:

wfRn
w Optional — The overall width of the display field, specified as a positive integer. Used to impose a uniform width (number of characters) for each element of dynarray. Different operations are performed if w is larger or smaller than the length of an element, as described in the FMT function.
f Optional — A fill character, specified as a single character. If the fill character is a number, the backslash (\), or the letters “L”, “R”, or “T” it must be enclosed in string delimiter quotes. You must specify w to use f. If you specify w, but do not specify f, it defaults to the space character.
R Optional — The letter “R” or “L” specifying right or left justification. This letter code is not case-sensitive. If you do not specify a letter code, FMTS defaults to left justification.
n Optional — The number of fractional digits to the right of the decimal place, specified as a positive integer. If you specify n, it must either be the only code in format, or it must be preceded by the letter “R” or “L”. If you do not specify n, FMTS defaults to number of fractional digits in string.

There are two basic uses of format:

  • To return fractional numbers in a standard form. FMTS can be used to round a fractional number to an integer or to a specified number of fractional digits. If the specified number of fractional digits is larger than the number of fractional digits in the element value, FMTS zero pads the additional digits.

  • To return strings in a standard form. FMTS can left justify or right justify a string and add a fill character before or after to make each element contain the same number of characters.

For further details on format codes, refer to the FMT function.

Examples

The following example uses “Rn” formatting to format the elements of a dynamic array so that all elements display 4 decimal digits. Note that both zero padding and rounding are performed as needed:

nums="1.2":@VM:"2.45":@VM:"3":@VM:"4.123456":@VM:"0"
PRINT FMTS(nums,"R4")
    ! Returns: 1.2000ý2.4500ý3.0000ý4.1235ý0.0000
Copy code to clipboard

The following example uses “wfL” formatting to format the elements of a dynamic array so that all elements display seven characters. Note that the ^ character is used as the fill character:

flints="FRED":@VM:"BARNEY":@VM:"WILMA":@VM:"PEBBLES"
PRINT FMTS(flints,"7^L")
    ! Returns: FRED^^^ýBARNEY^ýWILMA^^ýPEBBLES
PRINT FMTS(flints,"7^R")
    ! Returns: ^^^FREDý^BARNEYý^^WILMAýPEBBLES
Copy code to clipboard

See Also

Previous section FMT    FMULNext section