Str()
Convert a number to a character string.
Syntax
Str(<nNumber>, [<nLength>], [<nDecimals>]) --> cNumber
Arguments
<nNumber> --> is the numeric expression to convert to a character string.
<nLength> --> is the length of the character string to return, including decimal digits, decimal point, and sign.
<nDecimals> --> is the number of decimal places to return.
Returns
Str() returns <nNumber> formatted as a character string. If the optional length and decimal arguments are not specified, Str() returns the character string according to the following rules:
|
Results of Str() with No Optional Arguments | |
|
Expression |
Return Value Length |
|
Field Variable |
Field length plus decimals |
|
AsVal() |
Minimum of 3 digits |
|
Month()/Day() |
3 digits |
|
Year() |
5 digits |
Description
Str() is a numeric conversion function that converts numbers to character strings. Str() is like Transform() which formats numeric values as character strings using a template instead of using length and decimal parameters.
The inverse of Str() is AsVal() which converts character numbers to numerics.
Notes
If <nLength> is less than the number of whole number digits in <nNumber>, Str() returns asterisks instead of the number.
If <nLength> is less than the number of decimal digits required for the decimal portion of the returned string, CAPITAL rounds the number to the available number of decimal places.
If <nLength> is specified, but <nDecimals> is omitted (no decimal places), the return value is rounded to an integer.
Examples
Ltrim(Str(123))
* Result := '123.45'
LTrim(STR(123, 2))
* Result := '**'
LTrim(STR(123.456))
* Result := '123.456'
____________________________
Related Topics: