STR
STR returns the string representation of a floating point number in decimal notation.
The number passed to the STR function must use .
(period) as the decimal separator and
,
(comma) as the thousand separator. Any other decimal or thousand separators will cause
incorrect results.
This function is valid in both TM1® rules and TurboIntegrator processes.
Syntax
STR(number, length, decimal)
|
Argument |
Description |
|---|---|
|
number |
The floating point number being converted to a string. This number can contain a positive or negative sign. This number can contain decimal places. |
|
length |
The minimal length of the string to be returned., including sign, separators,
decimal, or decimal places. The length argument value should be a positive
number greater than If the length argument value is If the length argument value is a negative number, the function returns an empty string. If the count of digits in the number is less than the length argument value, the function inserts leading blank spaces to attain this length after inserting sign, separators, decimal, or decimal places. If the count of digits in the whole number exceeds the length
argument value and the decimal argument value is If the count of digits in the number exceeds
the length argument value and the decimal argument
value is greater than |
|
decimal |
The number of decimal places to include in the string representation. If this parameter is If the number specified has more decimal places than the decimal argument, the function result is rounded. If a negative number with decimals is specified, the function rounds the number accordingly (for example, -3 rounds to thousands and -6 rounds to millions), but returns the full number with trailing zeros to reflect the rounding. |
All arguments are required and you cannot pass empty argument values.
The STR function returns a string representation that uses a period (.) as the decimal separator.
STR is the counterpart of the NUMBR function where NUMBR(STR(x, length, decimal))
returns the original value (x) when provided the number of decimals suffices to represent the
fraction. The returned string representation does not contain any thousand separator. To format
numbers, use StringToNumber or StringToNumberEx.
Examples
| Function call | Number | Length | Decimal | Result |
|---|---|---|---|---|
| STR(3.14159, 6, 2) | 3.14159 | 6 | 2 | 3.14 |
| STR(-3.14159, 6, 0) | -3.14159 | 6 | 0 | -3 |
| STR(3.14159, 5, 3) | 3.14159 | 5 | 3 | 3.142 |
| STR(1000000, 4, 0) | 1000000 | 4 | 0 | 1000 Note that the number is truncated. |
| STR(1000000, 4, 2) | 1000000 | 4 | 2 | 1000000.00 Note that the number is not truncated because decimal is specified. |
| STR(10, 2, 4) | 10 | 2 | 4 | 10.0000 |
| STR(120536.74391, 8, 0) | 120536.74391 | 8 | 0 | 120536 The result includes left padding of two spaces to attain the specified length of 8. |
| STR(120536.74391, 5, 0) | 120536.74391 | 5 | 5 | 12053 The count of digits in the whole number exceeds the
length argument value and the decimal argument
value is |