padding negative numbers

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
vinnz
Participant
Posts: 92
Joined: Tue Feb 17, 2004 9:23 pm

padding negative numbers

Post by vinnz »

I have to do the reverse of what another op posted which is to pad a numbers with zeros.
Also, The first char needs to be '-' fro -ve numbers or blank for +ve numbers.

123.00 -> ' 00000123.00'
-25.30 -> '-00000025.32'
12 -> ' 00000012.00'
-0.45 -> '-00000000.45'

And I've written the following in the transformer and I feel like I've written a piece of clumsy code

Code: Select all

If DSLink2.testNum[1,1] = "-" 
Then 
"-":FMT(DSLink2.testNum[2,LEN(DSLink2.testNum)],"11'0'R2") 
Else  
" ":FMT(DSLink2.testNum,"11'0'R2")
Is there a better way to do this?

thanks in advance,
paul
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Perhaps

Code: Select all

If DSLink2.testNum[1,1] = "-" Then "-" Else " " : Fmt(Abs(DSLink2.testNum),"R%11")
"R2%11" is another way to write "11'0'R2".
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply