<< Click to Display Table of Contents >> Navigation: Available Functions > Str() |
Syntax
Str( <NumericValue1>, <NumericValue2>, <NumericValue3> )
Purpose
To return <NumericValue1> as a character value.
Parameters
<NumericValue1> is a numeric value that you wish to convert to character type.
<NumericValue2> is the length of the character value to return.
<NumericValue3> is the number of decimal places with which to format the numeric value before converting it to a character value.
Returns
A Character value.
Usage
This function allows you to take numeric fields (such as the .Donation_Total. field), and convert them to character values so that they may be combined with other character values.
Examples
During a report you wish to print the .Donation_Total. field within an opening and closing parenthesis. You could do this by entering the following expression for the Field Name/Expression of a report column:
"(" + Str( .Donation_Total., 10, 2 ) + ")"
In this example, <NumericValue2> is 10, which will cause the .Donation_Total. to be formatted within a character value that is ten characters wide. <NumericValue3> is 2, which will cause the .Donation_Total. to be formatted to two decimal places (which is what we would want for dollars and cents).
The only problem with the above example is that the dollar amounts would always be right-justified within the ten character width. Because of this, the output would look like this:
( 45.78)
( 265.82)
( 2634.38)
( 87243.29)
... And so on. If we wished to eliminate any spaces after the opening parenthesis, we could use the following expression:
"(" + LTrim( Str( .Donation_Total., 10, 2 ) + ")"
which would result in:
(45.78)
(265.82)
(2634.38)
(87243.29)
But what if we wanted the decimal points to still line up, and have no spaces between the opening parenthesis and the amount? We could use the following expression:
PadL( "(" + LTrim( Str( .Donation_Total., 10, 2 ) + ")", 12 )
With the above expression, we are using the "PadL()" function to right-justify the final result within a character value that is twelve characters wide (we use twelve since the open and close parenthesis require two additional spaces beyond the ten for the amount). The output would look like this on a report:
(45.78)
(265.82)
(2634.38)
(87243.29)