Page 1 of 1

DataStage DOUBLE convert to TEXT trailing zeros 2 dec

Posted: Fri Nov 30, 2018 1:53 pm
by iamcjej
I am trying to convert a column that is DOUBLE input containing dollars and cents to a text file with no leading zeros and trailing zeros out to 2 decimals places. I am attempting this via a Transformer Stage, Stage Variable, but it is not working. Tried multiple ways, more and more creative, yet nothing gives correct result. Any thoughts? Much appreciated.

If we use Fix Zero we get leading zeros which we don't want. If we use Suppress Zero we don't get trailing zeros. We want the combination.

Posted: Fri Nov 30, 2018 5:53 pm
by ray.wurlod
Use fix_zero in the stage variable.

Change the data type of the output column to VarChar, and use a Trim() function to trim the leading zeroes.

Code: Select all

Trim(svDecimalValue, "0", "L")

Posted: Thu Dec 06, 2018 7:35 am
by iamcjej
Thanks, I appreciate the response but I am still not getting the desired result. Did I misinterpret? Steps taken:

1. Input to the transformer stage:
TOTAL_REV, Double
2. Stage variable Derivations and Stage Variables:
Keep_These_Rows, TOTAL_REV, DXEchange1
trim(DXEchange1, "0","L"), DXEchange2
3. Transformer Stage Properties, Stage:
DXEchange1, VarChar, 20,2
DXEchange2, VarChar, 20,2
4. Output of the Transformer stage:
DXEchange1,
DXEchange2
The output text is still dripping trailing zeros, even the trim function is dropping leading zeros:

Posted: Sun Dec 09, 2018 6:35 pm
by ray.wurlod
The Trim() function, in that form, is intended to drop leading non-significant zeroes.

You may need an explicit DecimalToString() conversion to preserve the non-significant trailing zeroes.

Posted: Fri Dec 14, 2018 9:29 am
by iamcjej
Thank you. I have resolved my problem. Since Money should always be represented by decimal, I changed it to DECIMAL (20,2), then used a combination of this function in the Transformer stage to display them as strings.
Trim(TrimF(DecimalToString(inputLink)),"0","L");