STRING( ) function
Converts a numeric value to a character string.
Syntax
STRING(number, length <,format>)
Parameters
Name | Type | Description |
---|---|---|
number |
numeric |
The numeric 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. For example, "(9,999.99)" |
Output
Character.
Examples
Basic examples
Unformatted strings
Returns " 125.2":
STRING(125.2, 6)
Returns "25.2" (-1 is truncated because length is less than the number of digits and formatting characters in number):
STRING(-125.2, 4)
Returns " -125.2":
STRING(-125.2, 7)
Formatted strings
Returns " (125.20)":
STRING(-125.2, 10, "(9,999.99)")
Returns "25.20" (1 is truncated because length is less than the number of digits and formatting characters in number):
STRING(125.2, 6, "(9,999.99)")
Field input
Returns numeric values in the Employee_number field as character strings with a length of 10 characters. If required, the return value is padded or truncated:
STRING(Employee_number, 10)
Remarks
Padded and truncated return values
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 return value
- If number is longer than length, the return value is truncated from the left side
Formatting the return value
The optional format parameter adds formatting to the return value such as dollar signs, percent symbols, decimals, commas, negative indicators, or parentheses. The format must be enclosed in double quotation marks.
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.
Related functions
The STRING( ) function is the opposite of the VALUE( ) function, which converts character data to numeric data.