How to retain preceeding zeros in a decimal field?

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
hari4dsx
Participant
Posts: 14
Joined: Wed Feb 13, 2008 4:53 am

How to retain preceeding zeros in a decimal field?

Post 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.
Hari
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

It happens by default.
ragasambath
Participant
Posts: 12
Joined: Wed Oct 03, 2007 9:11 am
Location: London

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

Post 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
Regards

Raga
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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.
-craig

"You can never have too many knives" -- Logan Nine Fingers
zhzhs
Participant
Posts: 13
Joined: Mon Nov 13, 2006 10:40 pm
Location: china

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

Post 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)
I have a baby
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Again, there's no such thing as "converted into integer, with the preceeding zeroes retained".
-craig

"You can never have too many knives" -- Logan Nine Fingers
jgreve
Premium Member
Premium Member
Posts: 107
Joined: Mon Sep 25, 2006 4:25 pm

when is an integer not actually an integer?

Post 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.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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:
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
zhzhs
Participant
Posts: 13
Joined: Mon Nov 13, 2006 10:40 pm
Location: china

Post 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.
I have a baby
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You can make the target column a VarChar and assemble the string however you like.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
zhzhs
Participant
Posts: 13
Joined: Mon Nov 13, 2006 10:40 pm
Location: china

Post 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")
I have a baby
Post Reply