
Str Function
Data Kruncher May 15, 2014 10:09 AM (in response to joey)So 12345.1234 would yield "9", 123.45 would yield "5", 12.0 would yield "2" (or would it be "3"?) and 123.1 would yield "4"?
If so, that's a nasty challenge, now isn't it. :confused:

Str Function
joey May 15, 2014 10:09 AM (in response to Data Kruncher)Note quite. And, as an additional requirement I was stripping the decimal. 12345.1234 would yied "123451234". 12.0 would be "120" 123 would be "123". This is the burden of working with the mainframe.
The more I thought about it, I had to force the function to pass the number of decimal places as an arguement. If the model that calls the function doesn't pass the correct number, the results will be unpredictable (often zeros).
I'd love to hear others solutions and ideas to get arround this though.

Str Function
Data Kruncher May 15, 2014 10:09 AM (in response to joey)I'm close, but it's not perfect. "#.0" is the problem. Here's what I've got so far...
The value captured from the report is RptNum.
StrDec represents the decimal portion of RptNum, using:
Replace(Intrim(replace(str((abs(RptNumInt(RptNum)))*1000000000),"0"," "))," ","0")[/CODE]
The final Result field uses:
Trim(Str(Abs(int(RptNum))))StrDecIf(RptNum<0,"","+")[/CODE]
Hopefully this moves you ahead somewhat.

Str Function
Data Kruncher May 15, 2014 10:09 AM (in response to Data Kruncher)A pretty straightforward fix for the 12.0 case:
Trim(Str(Abs(Int(RptNum))))If(Len(StrDec)=0,"0",StrDec)If(RptNum<0,"","+")[/code]But if you need more decimal places than just the single forced significant digit, "0" above, then you could perhaps add a runtime parameter for the number of sigificant decimal places to use, and then build a lookup calculated field named FillZero:
2 00
3 000
4 0000
5 00000
6 000000[/code]Etcetera, as needed.
A nice little Excellike Repeat() function would have been good here, but that's not an option at the moment.
Then the formula above would become:
If(Len(StrDec)=0,FillZero,StrDec)+
If(RptNum<0,"","+")[/code]


