Problem with String to decimal

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
sshettar
Premium Member
Premium Member
Posts: 264
Joined: Thu Nov 30, 2006 10:37 am

Problem with String to decimal

Post by sshettar »

Hi All,

I have this job which is reading data as just one column
I parsed this filed based on the specified fields

I have this one field which should be of type decimal [7,2]
But when i convert the string to decimal it is giving as '0000.00'
though there is other values in it
here's one example

the data which is read as one field of type varchar() & length 320 is
'XA0 7888610000 010101050000008 112460007770000000000000000000000000000000000000000000000000000 '
And the field that should be decimal is extracted thi sway

StringToDecimal(DSLink2.VISIONDATA[78,7])
and i have defined it as datatype decimal length 7 scale 2
and within the field definition
Field Level
delimiter : none
Start position : 78

Decimal Type
Precision: 2
Field width: 7

The job runs successfully but the value that the above filed hold is
00000.00

where as the data it stores at that position is 0077700
Any input on how to fix this problem

Any help would be highly appreciated
just4geeks
Premium Member
Premium Member
Posts: 644
Joined: Sat Aug 26, 2006 3:59 pm
Location: Mclean, VA

Re: Problem with String to decimal

Post by just4geeks »

Hi,

I believe
DSLink2.VISIONDATA[78,7] is doing substring so you are getting exact 7 values '0000.00' from 78th position

I the arguments for StringToDecimal is (String,rtype)
where rtype is ceil or floor.


sshettar wrote:Hi All,

I have this job which is reading data as just one column
I parsed this filed based on the specified fields

I have this one field which should be of type decimal [7,2]
But when i convert the string to decimal it is giving as '0000.00'
though there is other values in it
here's one example

the data which is read as one field of type varchar() & length 320 is
'XA0 7888610000 010101050000008 112460007770000000000000000000000000000000000000000000000000000 '
And the field that should be decimal is extracted thi sway

StringToDecimal(DSLink2.VISIONDATA[78,7])
and i have defined it as datatype decimal length 7 scale 2
and within the field definition
Field Level
delimiter : none
Start position : 78

Decimal Type
Precision: 2
Field width: 7

The job runs successfully but the value that the above filed hold is
00000.00

where as the data it stores at that position is 0077700
Any input on how to fix this problem

Any help would be highly appreciated
Attitude is everything....
sshettar
Premium Member
Premium Member
Posts: 264
Joined: Thu Nov 30, 2006 10:37 am

Post by sshettar »

Thanks for the reply

I did try adding it to
StringToDecimal(DSLink2.VISIONDATA[78,7],'ceil')

But no change
it still reads '00000.00'
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Yes, [] is substring but you need to recheck the start position, your number starts at something more like 84 or 85.
-craig

"You can never have too many knives" -- Logan Nine Fingers
sshettar
Premium Member
Premium Member
Posts: 264
Joined: Thu Nov 30, 2006 10:37 am

Post by sshettar »

I'm sorry my output should look like
1124600 not 0077700
hence the start position is 78
mikegohl
Premium Member
Premium Member
Posts: 97
Joined: Fri Jun 13, 2003 12:50 pm
Location: Chicago
Contact:

Post by mikegohl »

try defining your target column to [9,2] or [7,0] and not [7,2]
Last edited by mikegohl on Thu Aug 21, 2008 2:48 pm, edited 2 times in total.
Michael Gohl
hsahay
Premium Member
Premium Member
Posts: 175
Joined: Wed Mar 21, 2007 9:35 am

Post by hsahay »

Hi,

you are cutting wrong positions.


try with

DSLink2.VISIONDATA[38,7], then it will give 0077700 for VarChar.

if you want decimals, you can change that based on your requirement.

hope it helps
vishal
sshettar
Premium Member
Premium Member
Posts: 264
Joined: Thu Nov 30, 2006 10:37 am

Post by sshettar »

Thank for all the prompt replies

Well i found a work around for this

I instead did the following
in the derivation for the field i gave

DSLink2.VISIONDATA[78,5]:'.':DSLink2.VISIONDATA[83,2]

and i read it as decimal 7.2
It worked for
though tis giving me the output i wanted ie 00777.00
Dont know if this is right???

Thanks
mikegohl
Premium Member
Premium Member
Posts: 97
Joined: Fri Jun 13, 2003 12:50 pm
Location: Chicago
Contact:

Post by mikegohl »

It was not clear that there was an implied decimal point. You could have divided the result by 100.0.
Michael Gohl
sshettar
Premium Member
Premium Member
Posts: 264
Joined: Thu Nov 30, 2006 10:37 am

Post by sshettar »

Well my data dint have any decimal point

Hence i put in a decimal point in order to make it easy for transformer to read it as decimal

Hope i cleared your doubt
Post Reply