Convert value from -00005.55 to -5.55

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

Marley777
Premium Member
Premium Member
Posts: 316
Joined: Tue Jan 27, 2004 3:26 pm

Convert value from -00005.55 to -5.55

Post by Marley777 »

Hi, would like to convert -00005.55 to -5.55. Field is a decimal field length of 5 and a scale of 2.

Thanks
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post by anbu »

Leading zeros does not affect the decimal value. You can assign your input directly to your target of Decimal(5,2)
You are the creator of your destiny - Swami Vivekananda
Marley777
Premium Member
Premium Member
Posts: 316
Joined: Tue Jan 27, 2004 3:26 pm

Post by Marley777 »

The end users do not want to see the leading zeroes. Out target is a file. so wondering how we can go from -00005.55 to -5.55?
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post by anbu »

Define your target as varchar
You are the creator of your destiny - Swami Vivekananda
Marley777
Premium Member
Premium Member
Posts: 316
Joined: Tue Jan 27, 2004 3:26 pm

Post by Marley777 »

We tried varchar but it did nothing came back as -00005.55

We also tried Trim(Convert(' ','',(Format.PAID)),"0","L") worked for positive numbers, but not negatives, negatives were unchanged.

Any other ideas

Thanks
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post by anbu »

Code: Select all

If Format.PAID < 0 Then '-':Trim(Convert(' ','',(-1*Format.PAID)),"0","L") Else Trim(Convert(' ','',(Format.PAID)),"0","L")
You are the creator of your destiny - Swami Vivekananda
Marley777
Premium Member
Premium Member
Posts: 316
Joined: Tue Jan 27, 2004 3:26 pm

Post by Marley777 »

That gives us ,-5.000000 Puts zeroes on the other side. works for positive, but not negative. Not sure how to get rid of the zeroes to the right now?
HariK
Participant
Posts: 68
Joined: Thu May 17, 2007 1:50 am

Post by HariK »

convert the negative into positive(multiply by -1), do the same conversion as you did for positive and then convert back to negative.
Marley777
Premium Member
Premium Member
Posts: 316
Joined: Tue Jan 27, 2004 3:26 pm

Post by Marley777 »

Still gives us the zeroes on the right of the decimal position.

Tried multiplying -00005.00 * -1 to get 00005.00, then applying the conversion, and then concatenating a negative sign on the front. It still came out -5.000000.

We still have the zeroes on the end.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Show us the precise expression that you used. This will enable our assistance to be more exactly targeted.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
arunkumarmm
Participant
Posts: 246
Joined: Mon Jun 30, 2008 3:22 am
Location: New York
Contact:

Post by arunkumarmm »

Can you try something like this:

If Input.Column < 0 Then '-' : Trim(Field(Input.Column,'-',2),'0','L') Else Trim(Input.Column,'0','L')
Arun
Marley777
Premium Member
Premium Member
Posts: 316
Joined: Tue Jan 27, 2004 3:26 pm

Post by Marley777 »

If we split the logic accross 3 stage variables it works. Our output is a varchar field. But not sure why we needed to do it this way; please read below.

example (the logic below works when splitting the formula)

svPaidIn
If Format.PAID < 0 Then Format.PAID * -1 Else Format.PAID

svPaid
Trim(Convert(' ','',(svPaidIn)),"0","L")

svPaidTarget
If Format.PAID < 0 Then '-':svPaid Else If svPaid[1,1] = "." Then "0":svPaid Else svPaid

but when we do the logic below it puts 0's to the right. Same formula as above, but not split accross multiple lines/stage variables like we saw in the previous example. Is it doing the Trim(Convert first them multiply by -1? Not sure why it doesn't do the correct order of operations when all together in one formula, but when we split it out it works?

svPaid
If Format.PAID < 0 Then Trim(Convert(' ','',(Format.PAID *-1)),"0","L") Else Trim(Convert(' ','',(Format.PAID)),"0","L")

svPaidTarget
If Format.PAID < 0 Then '-':svPaid Else If svPaid[1,1] = "." Then "0":svPaid Else svPaid
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

have you tried decimaltostring with suppress_zero as rtype?

Can't check it but you can give it a shot.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
akbar2002
Premium Member
Premium Member
Posts: 6
Joined: Wed Jul 11, 2007 11:34 am

Post by akbar2002 »

SV1 : StringToDecimal(column_name) --> DataType = VarChar
SV2 : Field(SV1,'.',1) --> DataType = Integer
SV3 : Right(SV1,2) --> DataType = VarChar

Derivation : SV2:'.':SV3 --> DataType = VarChar

Let me know if you see find any issues

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

Post by ray.wurlod »

Did you mean DecimalToString() ?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply