Click or drag to resize

_Str Function

Convert a numeric expression to a string.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.08
Syntax
 FUNCTION _Str(
	 nValue AS USUAL,
	 uLen AS USUAL,
	 uDec AS USUAL
) AS STRING
View Source

Parameters

nValue
Type: Usual
uLen
Type: Usual
uDec
Type: Usual

Return Value

Type: String
The 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:
X#
nNumber := 123.45
? Str(nNumber)                                                        //      123.45
? Str(nNumber, 4)                                                // 123.
? Str(nNumber, 2)                                                // **
? Str(nNumber * 10, 7, 2)                                        // 1234.50
? Str(nNumber * 10, 12, 4)                                //    1234.5000
? Str(nNumber, 10, 1)                                        //      123.5
? Str(123.45, -1)                                                // 123.45
? Str(123.45, -1, 2)                                        // 123.45
? Str(0.45000, 12, -1)                                        //      0.45000
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:
X#
? nNum
// displays identical to MyFunction() below
? MyFunction()
// displays identical to nNum above
// but internally they are not equal
? nNum = MyFunction()                                        // FALSE
// after rounding they are equal
? Round(nNum, 0) == Round(MyFunction(), 0)        // TRUE
// a Val(Str()) is also rounding
? Val(Str(nNum)) = Val(Str(MyFunction()))                // TRUE
Setting SetFloatDelta() to a higher value than before has the same effect:
X#
SetFloatDelta(0.1)
? nNum == MyFunction()                                        // TRUE
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:
X#
? Str(9,6,6)        => "******"
? Str(9,6,5)        => "******"
? Str(9,6,4)        => "9.0000"
? Str(9,6,3)        => " 9.000"
? Str(10,6,6)        => "******"
? Str(10,6,5)        => "******"
? Str(10,6,4)        => "******"
? Str(10,6,3)        => "10.000"
This example uses Str() to create an order with a compound key of order numbers and customer names:
X#
USE customer NEW
INDEX ON Str(NumOrders, 9) + Custname TO custord
See Also