_Str Function | |
Convert a numeric expression to a string.
Namespace:
XSharp.RT
Assembly:
XSharp.RT (in XSharp.RT.dll) Version: 2.19
Syntax FUNCTION _Str(
nValue,
uLen,
uDec
) AS STRING CLIPPER
[ClipperCallingConventionAttribute(new string[] { ... })]
public static string _Str(
Usual nValue = default,
Usual uLen = default,
Usual uDec = default
)
Request Example
View SourceParameters
- nValue (Optional)
- Type: Usual
- uLen (Optional)
- Type: Usual
- uDec (Optional)
- Type: Usual
Return Value
Type:
StringThe returned string with always have a DOT as decimal separator.
Remarks
Str() is commonly used to concatenate numbers to strings. Thus, it is useful for creating codes for items, such as part numbers, from numbers and for creating order keys that combine numeric and character data.
Str() is like Transform(), which formats numbers as strings using a mask instead of length and decimal specifications.
The inverse of Str() is Val() which converts numbers formatted as strings to numeric values.
Examples
These examples demonstrate the range of values returned by Str(), depending on the arguments specified:
1nNumber := 123.45
2? Str(nNumber)
3? Str(nNumber, 4)
4? Str(nNumber, 2)
5? Str(nNumber * 10, 7, 2)
6? Str(nNumber * 10, 12, 4)
7? Str(nNumber, 10, 1)
8? Str(123.45, -1)
9? Str(123.45, -1, 2)
10? Str(0.45000, 12, -1)
Often two numbers display the same results, but internally they have two different values stored in them. Thus an equality test will fail (return FALSE) unless you round each side. Here is an example:
1? nNum
2
3? MyFunction()
4
5
6? nNum = MyFunction()
7
8? Round(nNum, 0) == Round(MyFunction(), 0)
9
10? Val(Str(nNum)) = Val(Str(MyFunction()))
Setting SetFloatDelta() to a higher value than before has the same effect:
1SetFloatDelta(0.1)
2? nNum == MyFunction()
This functions returns a string of all asterisks when the Decimals parameter is > 0 and the Decimals parameter is > Length-2.
Also a string of all asterisks is returned when the number does NOT fit into the allocated space.
Example:
1? Str(9,6,6) => "******"
2? Str(9,6,5) => "******"
3? Str(9,6,4) => "9.0000"
4? Str(9,6,3) => " 9.000"
5? Str(10,6,6) => "******"
6? Str(10,6,5) => "******"
7? Str(10,6,4) => "******"
8? Str(10,6,3) => "10.000"
This example uses Str() to create an order with a compound key of order numbers and customer names:
1USE customer NEW
2INDEX ON Str(NumOrders, 9) + Custname TO custord
See Also