STR Function
Syntax
Arguments
- numberNumeric
The number to format.
- lengthNumeric
Default = 10. The number of characters in the Formatted_String. Refer to Number Formats for more information.
- decimal_placesNumeric
Default = 0. The number of characters after the decimal point in the Formatted_String. If you do not specify decimal places, STR() rounds the Number to the nearest whole number.
- number_formatCharacter
Default = "". The pattern to use when formatting Formatted_String. Values for Format are:
- Format Character
- Meaning
- $
Includes a leading currency symbol.
- %
Displays a number as a percentage.
- ,
Separates thousands with the thousands separator.
- *
Pad with leading '*' characters instead of spaces.
- X
Formats the number in words (e.g. for checkbook applications).
- L
Use lowercase (useful when formatting as words).
- W
Use proper case (first character uppercase, rest of word is lowercase).
- -
Use to change to position of the '-' for negative values.
- (
Use parentheses to represent negative numbers.
- B
Blank if zero format.
Returns
- Formatted_StringCharacter
Returns the value formatted as a string.
Description
Converts a number to a character string.
Discussion
STR() converts a Number to a right justified character string. The optional Length parameter determines the length of the string, and the optional Decimal_Places parameter specifies the number of decimal places. The length must allow space for decimals, the decimal point, and a - or + sign.
dim salary as n = 25500 ? str(salary) = " 25500" ? str(salary/10000,8,4) = " 2.5500" ? str(23434.34,12,2,"$,") = " $23,434.34"
Use the LTRIM() function to remove leading spaces before using the string in other operations.
STR format specs by example
- Format Spec
- Example Output
- "B"
123456.78 [blank if zero]
- "$("
$123,456.78
- "-$"
-$123,456.78
- "@("
$ 123,456.78
- ","
123,456.78
- ",("
(123,456.78)
- "%"
123,456.78%
- "XF"
Fifty six and 78/100
- "XF$"
Fifty six and 78/100 Dollars
- "$(B"
$123,456.78 [blank if zero]
- ",B"
123,456.78 [blank if zero]
- "%B"
123,456.78% [blank if zero]
- "XBF"
Fifty six and 78/100 [blank if zero]
- "X$(BF"
Fifty six and 78/100 Dollars [blank if zero]
- "$(*"
***$123,456.78
- ",*"
***123,456.78
- "X*F"
***Fifty six and 78/100
- "X$(*F"
***Fifty six and 78/100 Dollars
- "$(B*"
***$123,456.78 [blank if zero]
- ",B*"
***123,456.78 [blank if zero]
- "XB*F"
***Fifty six and 78/100 [blank if zero]
- "X$(B*F"
***Fifty six and 78/100 Dollars [blank if zero]
- "XC"
FIFTY SIX AND 78/100
- "X$(C"
FIFTY SIX AND 78/100 DOLLARS
- "XBC"
FIFTY SIX AND 78/100 [blank if zero]
- "X$(BC"
FIFTY SIX AND 78/100 DOLLARS [blank if zero]
- "X*C"
***FIFTY SIX AND 78/100
- "X$(*C"
***FIFTY SIX AND 78/100 DOLLARS
- "XB*C"
***FIFTY SIX AND 78/100 [blank if zero]
- "X$(B*C"
***FIFTY SIX AND 78/100 DOLLARS [blank if zero]
- "XL"
fifty six and 78/100
- "X$(L"
fifty six and 78/100 dollars
- "XBL"
fifty six and 78/100 [blank if zero]
- "X$(BL"
fifty six and 78/100 dollars [blank if zero]
- "X*L"
***fifty six and 78/100
- "X$(*L"
***fifty six and 78/100 dollars
- "XB*L"
***fifty six and 78/100 [blank if zero]
- "X$(B*L"
***fifty six and 78/100 dollars [blank if zero]
- "XW"
Fifty Six And 78/100
- "X$(W"
Fifty Six And 78/100 Dollars
- "XBW"
Fifty Six And 78/100 [blank if zero]
- "X$(BW"
Fifty Six And 78/100 Dollars[blank if zero]
- "X*W"
***Fifty Six And 78/100
- "X$(*W"
***Fifty Six And 78/100 Dollars
- "XB*W"
***Fifty Six And 78/100 [blank if zero]
- "X$(B*W"
***Fifty Six And 78/100 Dollars [blank if zero]
- "Uact0"
Accounting ' 234,123.23 ', ' (234,123.23)', ' - '
- "Uact1"
Accounting '$ 234,123.23 ', '$ (234,123.23)', ' - '
See Also