StringToDecimal

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
devsonali
Premium Member
Premium Member
Posts: 155
Joined: Sun Mar 18, 2007 2:31 pm

StringToDecimal

Post by devsonali »

Hello All,
I have a simple test job where I am trying to convert a string (CHAR 5) into Numeric ( 5,3) oracle table

RowGen-->Transformer-->Oracle

I referred the documentation but still feel that I am doing something fundamentally wrong here

Transformation is StringToDecimal(inputfield)
Output field = Numeric (5,3) Length 5 , Scale 3

Test data has


input , output , expected output

00010 , 10 , 00.010
10010 , 0 , 10.010
33333 , 0 , 33.333


Thank you for reading this .
Mike
Premium Member
Premium Member
Posts: 1021
Joined: Sun Mar 03, 2002 6:01 pm
Location: Tampa, FL

Post by Mike »

Looks like you have an implied decimal in your input. StringToDecimal would need an explicit decimal in the input to give you your expected result.

Mike
devsonali
Premium Member
Premium Member
Posts: 155
Joined: Sun Mar 18, 2007 2:31 pm

Post by devsonali »

Sorry , I think i didn't get you. I am doing a string to decimal conversion so , isn't the input field suppose to be a string ?
devsonali
Premium Member
Premium Member
Posts: 155
Joined: Sun Mar 18, 2007 2:31 pm

Post by devsonali »

I think i was able to search for a similar post (searched before but could not find it in first instance)

viewtopic.php?p=253139


I think in when I try to convert something like 33333 ,it is not possible to get the data as 5,3 as there are only 2 chars (digits) on the left of the decimal .

However is there a way to get results where 33333 gets converted into
33.333 in the output where the output column is defined as Numeric 5,3 ?

Thanks for any recommendations
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

As noted, because of the implied decimal you can't simple do the conversion and expect it to know what you want it to do. You'll need to do the conversion and then divide the result by 1000 to move the decimal over three places.

I seem to recall some functions allow you to specify the scale so it can do that for you automatically but this isn't one of them.
-craig

"You can never have too many knives" -- Logan Nine Fingers
devsonali
Premium Member
Premium Member
Posts: 155
Joined: Sun Mar 18, 2007 2:31 pm

Post by devsonali »

Thank you Craig , that works .
This resolved the issue , however , I am curious if somebody recollects the function that can allow us to specify the scale.
I will keep this post open for a while before marking it resolved.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I'm not saying that it might be anything that could help you here, just mentioned it more as an academic exercise. One example would be the Server FMT function that allows you to specify a value to "descale" when doing monetary or numeric formatting:
n[m]

n is a number, 0 through 9, that specifies the number of decimal places to display.
If you specify 0 for n, the value is rounded to the nearest integer. The output is padded with zeros or rounded to the nth decimal place, if required.

m specifies how to descale the value:
* A value of 0 descales the value by the current precision.
* A value of 1 through 9 descales the value by m minus the current precision.

If you do not specify m, the default value is 0. The default precision is 4.
-craig

"You can never have too many knives" -- Logan Nine Fingers
devsonali
Premium Member
Premium Member
Posts: 155
Joined: Sun Mar 18, 2007 2:31 pm

Post by devsonali »

Ok Thank you .
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

The server Oconv() function with "MD"-style conversion can also specify the number of decimal places. In your example.

Code: Select all

Oconv(InLink.MaskedValue, "MD3") 
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply