Alan Kirk wrote:
It's TM1's way of saying to you "I honestly don't know what the hell you're trying to do here, so here's my best guess".
The core problem is that neither of those functions make any real-world sense when used with those arguments. The Str() function has three arguments:
- The number being converted to a string;
- The length of the string. If necessary, the function inserts leading blank spaces to attain this length; and
- The number of decimal places to include in the function result.
The bit that's added to the description of the second argument is the clue. The argument should be greater than or equal to the number of digits in the number being converted. If the number of digits is more than that, the original will be returned as it is (but with the decimals rounded) down to a length value of 4. If the length value is 3 or below it just throws up its hands and walks away.
Why the coders of the function decided to set the limit at a length of 4 for this I have no idea but the fact remains that if the numbers are vastly longer than the length that you've specified then it makes no sense anyway. You want a length of 3 or 4 out of a 12 or 13 digit value; any particular 3 digits? The ones on the left? The ones on the right? A few plucked at random out of the middle? And then to those three or four digits we add a rounding to the right of the decimal place. No, that doesn't seem like a particularly useful formula result.
It may be an idea to specify what your objective is here. I suspect that what you actually need is some combination of SubSt(), NumberToString and/or NumberToStringEx() but without knowing the full context there is no way to tell.
Alan, thank you for reply.
I understand that this exercise looks as stupid as it gets
I promise you the original task had much more to do with real life than this one. I tried to simplify it and get to the core of the problem.
I am sorry if it seemed that I did not read the reference manual on STR function - I assure you I did several times. Your explanation (
The argument should be greater than or equal to the number of digits in the number being converted) should have been there, but it's not. It just doesn't make sense to me. I mean - the empty string for 'R'.
And the arbitrary choice of Length of 4, but not 3 for different kinds of behavior does not make any sense either.
When It says that the second argument is Length - I expect Str (123456789.888,3,1) to produce '123', or '789', or even '9.9'. But not the empty string, or the whole string like in case with 'P'. Both 'P' and 'R' seem to use Length in some very unexpected way. And to actually get '123' I have to do it like "SUBST (TRIM (Str (var,15,0)),1,3)". And to get "9.9" would involve LONG and some calculation
In short - the function should be described better. I hope we can agree on that
Regarding the actual problem - there was an hour of frustration about things not mapping right, and then a workaround solution, which works even better. And I learned a couple tricks along the way, so it's a happy end story