Page 1 of 1

Fixed width file

Posted: Tue Mar 15, 2011 9:41 pm
by krisna
Hi All,

My target is a file which contains amount columns of 22 width. 16 for integer part, 1 for decimal point, 4 for decimal digit. 1 for sign.
for example : 0000000000000000.0000, if we have -ve sign it should be -0000000000000000.0000.
My question is if it is a +ve number it should have leading space but I'm getting trailed space.
how to achieve a leading space if it is a +ve number.
Thanks in advance

Posted: Tue Mar 15, 2011 10:08 pm
by jwiles
If your source is already a string,

if left(number,1) <> '-' then ' ' : left(number,21) else number

However, if your source is a decimal, just place it in a decimal (20,4) column and use DecimalToString(). The default conversion should give you what you're looking for.

Regards,

Posted: Wed Mar 16, 2011 12:05 am
by krisna
for example from source table x and y columns had values like 234.5 and -145.64 then in file it should display as
0000000000000234.5000-0000000000000145.6400
(if it is positive number it should have a leading space so that the total width will be 22 characters.)
(if it is negative number with sign i will get 22 characters).
Thanks in advance

Posted: Wed Mar 16, 2011 1:11 am
by krisna
i made a mistake that using of trim with DecimalToString() function. After removing that it worked fine.

Posted: Wed Mar 16, 2011 1:14 am
by krisna
Thanks jwiles