Page 1 of 1

padding negative numbers

Posted: Mon Apr 26, 2004 10:35 am
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

Posted: Mon Apr 26, 2004 11:46 pm
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".