STRING( ) function

Converts a numeric value to a character string.

Syntax

STRING(number, length <,format>)

Parameters

number

Numeric. The value to convert to a string.

length

Numeric. The number of characters in the output string.

format

Optional. Character. The formatting to apply to the output string specified as a quoted string.

Output

Character.

Remarks

You can use this function to convert numeric data to character data. The function is commonly used to convert numeric fields for use with commands, such as CLASSIFY, that require character fields.

STRING( ) converts number into a character string of the length specified in length. If number is shorter than length, leading spaces are added to the output. If number is longer than length, the output is truncated from the left side.

The optional format parameter adds formatting to the output such as dollar signs, percent symbols, decimals, commas, negative indicators, or parentheses. The format parameter must be enclosed in double quotes. The digit 9 acts as a placeholder for digits to format. Ensure that you have the correct number of 9s for proper display. You also need to account for decimals and formatting characters, such as dollar signs and brackets for negative numbers, when you specify the value for the length parameter.

The STRING( ) function is the opposite of the VALUE( ) function, which converts character data to numeric data.

Examples

Example Return value

STRING(125.2, 7)

“  125.2”

Two leading spaces are added because length is greater than the number of digits and formatting characters in number.

STRING(-125.2, 4)

“25.2”

“-1” is truncated because length is less than the number of digits and formatting characters in number.

STRING(-125.2, 7)

“ -125.2”

The number value is converted to a string with one leading space.

STRING(-125.2, 10, "(9,999.99)")

“  (125.20)”

The number value is converted to a string with two leading spaces.

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

25.20

1 is truncated because length is less than the number of digits and formatting characters in number.

To create a field that converts the PACKED field Customer to a string so that it can be used as a key field, specify the following:

STRING(Customer, 8)

Related reference
VALUE( ) function


(C) 2013 ACL Services Ltd. All Rights Reserved. | Send feedback