Page 1 of 1

How to retain preceeding zeros in a decimal field?

Posted: Sat Aug 15, 2009 1:59 am
by hari4dsx
Input field is a decimal (eg. 00012.)..
This is to be converted into integer, with the preceeding zeroes retained.

Does anyone have any solution for this...?


Thanks in advance.

Posted: Sat Aug 15, 2009 5:19 am
by Sainath.Srinivasan
It happens by default.

Re: How to retain preceeding zeros in a decimal field?

Posted: Sat Aug 15, 2009 10:07 am
by ragasambath
hari4dsx wrote:Input field is a decimal (eg. 00012.)..
This is to be converted into integer, with the preceeding zeroes retained.

Does anyone have any solution for this...?


Thanks in advance.
Hari,

Do you want to retain the preceding zero's in the output ?

if so use FMT function of BASIC Transformer

Posted: Sat Aug 15, 2009 10:18 am
by chulett
Those leading zeroes are an artifact of the Viewer, they're not stored. You'll need to target a string field if you really 'need' to keep them.

Re: How to retain preceeding zeros in a decimal field?

Posted: Mon Aug 17, 2009 9:50 am
by zhzhs
hari4dsx wrote:Input field is a decimal (eg. 00012.)..
This is to be converted into integer, with the preceeding zeroes retained.

Does anyone have any solution for this...?


Thanks in advance.
U can try

substr("00000":link.column,-5,5)

Posted: Mon Aug 17, 2009 10:00 am
by chulett
Again, there's no such thing as "converted into integer, with the preceeding zeroes retained".

when is an integer not actually an integer?

Posted: Mon Aug 17, 2009 1:17 pm
by jgreve
I would suggest that your requirements are unclear.
In your situation, I would push back on my requirements
source and make them clarify what they mean by "integer".

If you are talking about hardware supported integers (which is
what technical people assume given the phrase "converted into
integer"), then leading zeros are always retained.

Your example used 00012. So if we encode that as a 16 bit integer,
you will get this somewhere on your disk:
0000 0000 0000 1110 (base-2)

Look at all those leading zeros.
Nice, aren't they.
And you get them for free simply by defining your target as type=integer.
(32-bit, 64-bit and larger integers are left as an exercise for the reader :-) )

So in this case, you could go back to your source and
say "Yes we are retaining leading zeros."

But if they really need to see the zero characters (e.g. char( 48 ) )
then they really need some kind of CHAR type field that happens to
hold only digits but no decimal point.


If they expect binary coded decimals or some other kind of integer
encoding, then you have a similar situation.

It pretty much depends on what you mean by "integer format".

Good luck!

hari4dsx wrote:Input field is a decimal (eg. 00012.)..
This is to be converted into integer, with the preceeding zeroes retained.

Does anyone have any solution for this...?


Thanks in advance.

Posted: Mon Aug 17, 2009 5:03 pm
by ray.wurlod
I'm surprised you didn't throw twos-complement versus ones-complement into that comprehensive discussion. Or Big-Endian versus Little-Endian (so that "leading" suddenly becomes problematic as a term).
:wink:

Posted: Tue Aug 18, 2009 12:06 am
by zhzhs
i have the same question,a column is decimal(10,2)
for example:

the data is 12000

output of the sequence file will be 00012000.00

but i need 12000.00

what can i do?
friends.

Posted: Tue Aug 18, 2009 1:12 am
by ray.wurlod
You can make the target column a VarChar and assemble the string however you like.

Posted: Tue Aug 18, 2009 9:39 am
by zhzhs
ray.wurlod wrote:You can make the target column a VarChar and assemble the string however you like. ...
thanks
i have known the way.
just
trim(decimaltostring(dslink.col),"0","L")