You are here: Functions > STRING()

STRING()

STRING() converts a numeric or elapsed time expression or field value into a string of characters.

Use STRING() to convert a numeric expression or field value to character format for use as a key field in an Analyzer command, such as Summarize or Join.

STRING() selects data from left to right (most significant digit to least significant digit). If a string length is specified that is shorter than the underlying data, only the most significant digits are selected to fill the string length. If a string length is specified that is longer than the underlying data, leading blanks are applied to fill the string length.

Function Format

STRING(N|E,# <,C>)

STRING() converts the numeric expression or field value N, or the elapsed time expression or field value E, into a string of length #. For numeric expressions or field values, the resulting string has a leading minus sign if N is negative and has the same number of decimal places as N (unless otherwise specified by the optional numeric format C).

For numeric expressions or field values, you can specify an optional numeric format C as a third parameter to format the numerical result of the function. Ensure that the format is is a valid character expression. The optional numeric format C is not applicable to elapsed times and, if included, will be ignored.

For details on formatting, refer to Numeric Fields.

If the resulting string is shorter than #, leading blanks are added. If the resulting string is longer than #, trailing characters are truncated without notification.

For numeric expressions and fields, STRING() is the opposite of VALUE().

Numeric Expressions or Fields

STRING(125.2,6) = " 125.2"

STRING(-125.2,5) = "-125."

STRING(-125.2,6) = "-125.2"

STRING(-125.2,7) = " -125.2"

These examples show the use of the optional numeric format parameter:

STRING(-125.2,9, "(9,999.99)") = " (125.20)"

STRING(-125.2,6, "(9,999.99)") = "(125.2"

To create a key character field that converts a PACKED field (CustNo) to a string with a length of 8, specify:

STRING(CustNo,8)

Elapsed Time Expressions or Fields

STRING(‘e4/16:25:17‘,15) = "4 Days 16:25:17"

STRING(‘e4/16:25:17‘,6) = "4 Days"