Returns the character equivalent of a numeric expression.
STR(nExpression [, nLength [, nDecimalPlaces]]) |
Parameters
- nExpression
- Specifies the numeric expression to evaluate.
- nLength
-
Specifies the length of the character string returned. If nLength is omitted, nLength defaults to 10 characters.
Note: If the expression contains a decimal point, the length includes one character for the decimal point and one character for each digit in the character string.
- nDecimalPlaces
-
Specifies the number of decimal places in the character string returned. To specify the number of decimal places using nDecimalPlaces, you must include nLength. If nDecimalPlaces is omitted, the number of decimal places defaults to zero (0).
Note: Visual FoxPro contains a limit of 16 digits of precision in numeric calculations. For more information about numeric precision in Visual FoxPro, see Visual FoxPro System Capacities.
Return Value
Character data type. STR(В ) returns a character string equivalent to the specified numeric expression.
Depending on certain conditions, STR(В ) can return the following:
-
If you specify fewer decimal places than exist in nExpression, the return value is rounded up. To round results to the nearest decimal place instead of upward, include the ROUND(В ) function. For more information, see ROUND(В ) Function.
-
If nExpression is an integer, and nLength is less than the number of digits in nExpression, STR(В ) returns a string of asterisks, indicating numeric overflow.
-
If nExpression contains a decimal point, and nLength is equal to or less than the number of digits to the left of the decimal point, STR(В ) returns a string of asterisks, indicating numeric overflow.
-
If nLength is greater than the length of the value evaluated by nExpression, STR(В ) returns a character string padded with leading spaces.
-
If nExpression has Numeric or Float type, and nLength is less than the number of digits in nExpression, and , STR(В ) returns a value using scientific notation.
Examples
Example 1
In the following example, STR(В ) evaluates 1.154994 as a character expression, specifies a length of 8 characters and the same number of decimal places that the specified expression contains, and displays 1.154994 using the ? command.
В | Copy Code |
---|---|
? STR(1.154995,8,6) |
Example 2
In the following example, STR(В ) evaluates 1.154994 as a character expression and specifies a length of 8 characters and 2 decimal places, four fewer decimal places than the specified expression contains. STR(В ) displays 1.16 using the ? command, which represents 1.154994 rounded upward.
В | Copy Code |
---|---|
? STR(1.154995,8,2) |
Example 3
In the following example, STR(В ) includes the ROUND(В ) function, evaluates 1.154994 as a character expression, and specifies a length of 8 characters 2 decimal places, four fewer decimal places than the specified expression contains. STR(В ) displays 1.15 using the ? command, which represents 1.154994, rounded to the nearest significant digit.
В | Copy Code |
---|---|
? STR(ROUND(1.154995,2),8,2) |