Page 1 of 1

Problem while using Fmt function

Posted: Fri Feb 02, 2007 8:56 am
by sumesh.abraham
Hi All,

I'm reading a record from a sequential file which has a numeric value.
For eg: If the input is a negative number as -123456, the output should be -00000123456.00000(11 digits after '-' sign and five digits after decimal point).
If the input is a positive number as 123456, the output should be
000000123456.00000 (12 digits before decimal point nd five digits after decimal point).

I tried Fmt function, but i'm confused how to padd zeros to left and right side simultaneously. In the transformer i've declared the Length as 18, scale as 5 and Display as 18.
The derivation is

Code: Select all

If IsNull(DSLink3.Field001) Then 000000000000.00000 Else If Substrings(DSLink3.Field001,1,1)="-" Then  "-":Fmt(Substrings(DSLink3.Field001,2,10),"12'0'L") Else ""
Is it possible to use 'L' and 'R' together in Fmt function.

Thanks in advance,
Sumesh

Posted: Fri Feb 02, 2007 9:10 am
by ArndW
Sumesh,

You don't need to use the L and R functions, or even any string formatting options at all, you can use FMT(DSLink3.Field001,'18"0"R5')

Posted: Fri Feb 02, 2007 9:38 am
by sumesh.abraham
Thanks.

But, when i use the following inputs output is not correct.

Code: Select all

Input: -1234. Output :0000000-1234.00000
Similiarly  1234:1234.00000
Why the negative sign is coming after zeros?
For positive number the output is not correct.

Code: Select all

-12345678901234:0-12345678901234.0
For long input the output is not proper.
The expression which i used is as follows.

Code: Select all

If IsNull(DSLink3.Field001) Then 000000000000.00000 Else If Substrings(DSLink3.Field001,1,1)="-" Then  Fmt(DSLink3.Field001,'18"0"R5') Else  

Fmt(DSLink3.Field001,'18"0"R5') 
Thanks a lot,
Sumesh

Posted: Fri Feb 02, 2007 9:48 am
by DSguru2B
Try this

Code: Select all

If IsNull(DSLink3.Field001) Then 000000000000.00000 Else If Substrings(DSLink3.Field001,1,1)="-" Then  "-": FMT(DSLink3.Field001[2,Len(input.key1)-1],'18"0"R5') Else Fmt(DSLink3.Field001,'18"0"R5')

Posted: Fri Feb 02, 2007 9:51 am
by garthmac
Add in an extra little part (Iconv(DSLink3.Field001,"MCN"):

Ans = If DSLink3.Field001[1,1]="-" Then "-":Fmt(Iconv(DSLink3.Field001,"MCN"),'18"0"R5') Else Fmt(DSLink3.Field001,'18"0"R5')

Posted: Fri Feb 02, 2007 11:17 am
by ArndW
You probably have a PRECISION of 14 set, so using FMT and a number with more digits is not going to work correctly.

Try

Code: Select all

IF DSLink3.Field001<0 THEN -':FMT(ABS(DSLink3.Field001),'11"0"R'):'.00000' ELSE FMT(DSLink3.Field001,'12"0"R'):'.00000'
Note I used the ABS() function in case the sign is trailing in the input.