Page 1 of 1

Decimal Rounding based on Parameter

Posted: Mon Jan 09, 2012 6:22 am
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

Posted: Mon Jan 09, 2012 3:27 pm
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.

Posted: Mon Jan 09, 2012 4:39 pm
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,

Posted: Tue Jan 10, 2012 4:34 am
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.