Formatting Decimal to String conversion

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
blewip
Participant
Posts: 81
Joined: Wed Nov 10, 2004 10:55 am
Location: London

Formatting Decimal to String conversion

Post by blewip »

I am performing a type conversion from a Float to a String using the following

Code: Select all

Trim(DecimalToString(DSLink2.NOMIN_QTY,"fix_zero,suppress_zero"))
 
This works fine apart from the fact that I have no control over the number of decimal places.

For example the output may look like 14256.43676

When I would want it to look like 14256.44

Is there a way to do this?
amsh76
Charter Member
Charter Member
Posts: 118
Joined: Wed Mar 10, 2004 10:58 pm

Post by amsh76 »

Why don't you round it to two decimal places first, and then do the conversion from float to string.
blewip
Participant
Posts: 81
Joined: Wed Nov 10, 2004 10:55 am
Location: London

Post by blewip »

Thanks, yes that does kinda work. The Float is already defined as 15,2, however the scale may be meaningless for a Float. However if I convert the Float to a Decimal 15,2 and then do the DecimalToString in another Transformer this does indeed work (an extra transformer though).

I can also do the following

Code: Select all

Trim(DecimalToString((Fabs ((DSLink2.NOMIN_QTY*100))/100),"fix_zero,suppress_zero")) 
This rounds to two decimal places first as well and this works fine (in same transformer). It just seems a bit long winded.

I was hoping they'd be an easier way. The online manual gives the following arguments for the DecimalToString and I was hoping one of these might help, however I can't get any of them to work (except fix_zero). Also suprisingly the suppress_zero is not documented, is it documented anywhere else, how did anyone find this argument?

Code: Select all

number (decimal)
[ fixzero(int8)]
[prefix (string)]
[prefixlen (int32)]
[suffix (string)]
[suffixlen (int32)](
blewip
Participant
Posts: 81
Joined: Wed Nov 10, 2004 10:55 am
Location: London

Post by blewip »

I had a few problems with the old solution, and I found a better way. There appears to be a new function DFloatToStringNoExp, this converts to string. doesn't give you an exponential and allow you you have control over the number of decimal places.

Code: Select all

DFloatToStringNoExp(DSLink2.FLOAT2DECI,6)
I sure people are using it, but it just doesn't appear in the documentation.

I also wanted to recipricol of a Float and found that it was better to convert to a String and then do the Maths.

Code: Select all

1/DFloatToStringNoExp(DSLink2.FLOAT2DECI,6)
Seems slightly odd, but 1/100 was giving me 0.0099999999 before.
Post Reply