Decimal Rounding based on Parameter

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
pksahu
Participant
Posts: 29
Joined: Wed Jul 25, 2007 5:07 am

Decimal Rounding based on Parameter

Post by pksahu »

Hi Friends,
I am trying to rounding of a Decimal based on a Parameter, which will give the length of digits after decimal points.
When I am trying to use DecimalToDecimal() function, I need to use the Datatype as required, so I am not able to provide the Parameter for Rounding.

Any idea how I can round the decimal based on parameter is much appriciated.

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

Post by ray.wurlod »

I suspect this is not possible. What have you tried, and with what result?

Have you considered a Modify stage? Pretty much everything in a Modify stage can be parameterized.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
jwiles
Premium Member
Premium Member
Posts: 1274
Joined: Sun Nov 14, 2004 8:50 pm
Contact:

Post by jwiles »

One possible solution would be to multiply your value by an appropriate power of 10, round the number and then divide by the same power of 10. Example:

Number of digits requested: 3
10**3 = 1000

Value: 12.45823
Value*1000 = 12458.23
Rounded = 12458.00
Rounded/1000 = 12.45800

This is simply one way to handle it through only math, but does not adjust the actual schema of the column. If required as well, that would require the modify solution proposed by Ray. The math can be done in stage variables, just ensure that they are defined large enough to handle the results of the multiplication and division.

Regards,
- james wiles


All generalizations are false, including this one - Mark Twain.
pksahu
Participant
Posts: 29
Joined: Wed Jul 25, 2007 5:07 am

Post by pksahu »

Thanks James.
The scenarios is like below: I have some derivation based on The Rate,Qty, Discount and then doing some percentage calculation. After that based on the [b]Currency precission[/b], I am doing the round up.

By applying your math formula, it worked perfectly.
Thanks a lot for all the help. Much appriciated.
Post Reply