Conversion from 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

Nagac
Premium Member
Premium Member
Posts: 127
Joined: Tue Mar 29, 2011 11:39 am
Location: India

Conversion from string to decimal

Post by Nagac »

Hi

I have data coming in character format like 98789.99. After reading this, i need to sum up all these values in Aggregator stage. For that i tried modify stage to convert string to decimal. i got the error as below
Modify_319: When checking operator: When binding output schema variable "outRec": When binding output interface field "Filed_Name" to field "Filed_Name": Conversion from source type "string[9]" to result type "decimal[1,0]": Possible range limitation.
I used like this :
INSURANCE_LIABILITY_AMOUNT:decimal = decimal_from_string (INSURANCE_LIABILITY_AMOUNT)
abhilashnair
Participant
Posts: 284
Joined: Fri Oct 13, 2006 4:31 am

Post by abhilashnair »

You need to mention the Length and scale in modify stage output metadata as otherwise it will take the default value. The error is because the incoming data is of length 9 and you have not mentioned any length or scale in the modify stage metadata
Nagac
Premium Member
Premium Member
Posts: 127
Joined: Tue Mar 29, 2011 11:39 am
Location: India

Post by Nagac »

Thanks mate,

I have given the length and scale in output metadata in modify stage
abhilashnair
Participant
Posts: 284
Joined: Fri Oct 13, 2006 4:31 am

Post by abhilashnair »

Nagac wrote:Thanks mate,

I have given the length and scale in output metadata in modify stage
And....? Is the issue resolved ?
Nagac
Premium Member
Premium Member
Posts: 127
Joined: Tue Mar 29, 2011 11:39 am
Location: India

Post by Nagac »

Sorry, i didn't reply properly.

Its not resolved. i got the above error after i mention precisio, and scale in output metdata in modify stage.
Nagac
Premium Member
Premium Member
Posts: 127
Joined: Tue Mar 29, 2011 11:39 am
Location: India

Post by Nagac »

I used modify stage before aggregating the data.
Nagac
Premium Member
Premium Member
Posts: 127
Joined: Tue Mar 29, 2011 11:39 am
Location: India

Post by Nagac »

I have changed it in Transformer and not its fine.

But i am facing one more issue that After Aggregation i used modify stage to convert double to decimal using default like Column_Name=Column_Name. It is giving the proper result, but its not adding zeros after decimal point if the data is rounded eg: 100.00 it is showing only 100, 100.10==>100.1.

I need to display in 100.00 format.

Is it possible?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Yes, but remember that leading and trailing non-significant zeroes are not actually part of a Decimal number. Therefore, the display specifications are applicable only when the target data type is string. You could try applying a DecimalToDecimal() function with scale of 2 in the metadata.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Nagac
Premium Member
Premium Member
Posts: 127
Joined: Tue Mar 29, 2011 11:39 am
Location: India

Post by Nagac »

Thanks Ray,

I did in modify stage as below

I am using below syntax in modify stage to keep 2 decimal places as scale. Even it is 00 it should as 00.00
I used syntax as:
Total_Record_Count = DecimalToDecimal(Total_Record_Count,"round_inf")


I am getting error like:
Error parsing modify adapter: Error in binding: Unknown conversion: DecimalToDecimal
Expected destination field selector, got: ")"; input:
Total_Record_Count = DecimalToDecimal(Total_Record_Count,"round_inf")



Input is decimal format and output also decimal format
Nagac
Premium Member
Premium Member
Posts: 127
Joined: Tue Mar 29, 2011 11:39 am
Location: India

Post by Nagac »

I have done this using decimal_from_decimal [round_inf]() in modify stage. But the result is same as earlier.

Can anyone tell how to do this?
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

As Ray noted, display formats are only valid when the target data type is string.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Nagac
Premium Member
Premium Member
Posts: 127
Joined: Tue Mar 29, 2011 11:39 am
Location: India

Post by Nagac »

i have given decimaltodecimal(field) and give metada as 10,2

But it is giving sama like 100

i need 100.00

i dont need to it to be in decimal format can be any, so anybody give me suggestions
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

As already noted, a string target combined with the DecimalToString() function.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Nagac
Premium Member
Premium Member
Posts: 127
Joined: Tue Mar 29, 2011 11:39 am
Location: India

Post by Nagac »

After using thse DecimalToString() function it is giving 00100.00.

I used Trim(Field,'0','L') to remove the left side zero's. it's not removing zero's. it is giving same as 00100.00
Nagac
Premium Member
Premium Member
Posts: 127
Joined: Tue Mar 29, 2011 11:39 am
Location: India

Post by Nagac »

I used Same function in other transformation, it worked fine. But dont know why it is not working here.

FYI my stages: Input-->Aggregator(Here i am summing the data)-->Transformer
Post Reply