Decimal 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
reachmexyz
Premium Member
Premium Member
Posts: 296
Joined: Sun Nov 16, 2008 7:41 pm

Decimal conversion

Post by reachmexyz »

Hello all,

I am getting a decimal number like 0000345.2343 and i am trying to convert the decimal to string and trim the zeros. To conver to string, i have used decimaltostring(0000345.2343,"fix_zero") and ran the job. I am getting "Conversion error calling conversion routine string_from_decimal data may have been lost" error and data is getting lost.
Please let me know how can i convert a decimal to String and later trim the leading zeros.
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post by anbu »

Code: Select all

Trim(field,'0','L')
You are the creator of your destiny - Swami Vivekananda
reachmexyz
Premium Member
Premium Member
Posts: 296
Joined: Sun Nov 16, 2008 7:41 pm

Post by reachmexyz »

anbu wrote:

Code: Select all

Trim(field,'0','L')
This will not work on a decimal directly.
Assuming decimal is 00023.22 and its schema is (precision=7, length=2),
even after trim(00023.22), the output will be 0000023.22 . Decimal number just fills in the precision and scale and doesnt care trim function.

Thats why i wish to convert the decimla to strign and then use trim function on that string.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Which is what was being suggested - trim the resulting string as shown.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

reachmexyz wrote:
anbu wrote:

Code: Select all

Trim(field,'0','L')
This will not work on a decimal directly.
Have you tried it? Decimal to string is an implicit conversion, so it should work.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
marpadga18
Premium Member
Premium Member
Posts: 96
Joined: Fri Aug 20, 2010 8:51 am

Post by marpadga18 »

ray.wurlod wrote:
reachmexyz wrote:
anbu wrote:

Code: Select all

Trim(field,'0','L')
This will not work on a decimal directly.
Have you tried it? Decimal to string is an implicit conversion, so it should work.
I tried this Trim and converting from decimal to string also then also it is not is not working. Is there any other solution for this
Thanks,
M
jwiles
Premium Member
Premium Member
Posts: 1274
Joined: Sun Nov 14, 2004 8:50 pm
Contact:

Post by jwiles »

Try this instead:

Code: Select all

Stage Variable svDecimal varchar()
derivation:   field

Output Link or another Stage Variable:
Left(svDecimal,1) : Trim(Right(svDecimal,8),'0','L')
It's that pesky sign byte...the 0's are not leading because of it.

The length 8 in the Right() function is based on the instrinsic conversion result: (decimal length)+2-1. You could use Len(field)-1, but since the string will always be the same length (coming from the same decimal) that just wastes CPU.

Regards,
- james wiles


All generalizations are false, including this one - Mark Twain.
Post Reply