Negative Number representation needs to be modified
Moderators: chulett, rschirm, roy
-
- Premium Member
- Posts: 23
- Joined: Wed Sep 10, 2008 4:46 pm
- Location: USA
Negative Number representation needs to be modified
Hi All,
Values for a source column in one of my job are as follows:
123.45-
985.24
234.67-
875.89
123.45- represents a negative number ( -123.45)
I need to look for - at the end and if found convert this number to -123.45 so that I can perform mathematical calculations with this value.
So my output should be:
-123.45
985.24
-234.67
875.89
Can anyone please suggest how this can be achieved?
Thanks a lot for all your help and guidence.
Values for a source column in one of my job are as follows:
123.45-
985.24
234.67-
875.89
123.45- represents a negative number ( -123.45)
I need to look for - at the end and if found convert this number to -123.45 so that I can perform mathematical calculations with this value.
So my output should be:
-123.45
985.24
-234.67
875.89
Can anyone please suggest how this can be achieved?
Thanks a lot for all your help and guidence.
Focus on ABC: Audit , Balance and Control..
-
- Premium Member
- Posts: 23
- Joined: Wed Sep 10, 2008 4:46 pm
- Location: USA
Can you define that part of the data as a separate field? If so then just check that field directly. If you can't, you check the last character of the field and then multiply the rest. Assuming the latter:
The "[]" are the substring operators and a single position by itself denotes from the end of the string. So, it checks to see if the last character is "-" and if so, take everything else (from 1 to the end -1) and multiplies it. You may need to trim your field before the check to make it work correctly. Or you can use the Index() function to detect the minus sign and take everything before it for the math part:
Index returns the position of the found character and a non-zero value equates to "true" so it also works as a boolean. You should do the check in a stage variable and reference that in the expression so you don't have to compute it twice.
Code: Select all
If Link.AmountField[1] = "-" Then
Link.AmountField[1,Len(Link.AmountField)-1) * -1
Else
Link.AmountField
Code: Select all
If Index(Link.AmountField,"-") Then
Link.AmountField[1,Index(Link.AmountField,"-")-1) * -1
Else
Link.AmountField
Last edited by chulett on Wed Apr 15, 2009 8:45 am, edited 1 time in total.
-craig
"You can never have too many knives" -- Logan Nine Fingers
"You can never have too many knives" -- Logan Nine Fingers
I would do something like
Code: Select all
If Index(Link.AmountField,"-") Then
CONVERT('-','',Link.AmountField) * -1
Else
Link.AmountField
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
-
- Premium Member
- Posts: 23
- Joined: Wed Sep 10, 2008 4:46 pm
- Location: USA
-
- Premium Member
- Posts: 425
- Joined: Sat Nov 19, 2005 9:26 am
- Location: New York City
- Contact:
Re: Negative Number representation needs to be modified
Hi, Try this
Oconv("123456-", "MC/N") : Oconv("123456-", "MCN")
Oconv("123456-", "MC/N") : Oconv("123456-", "MCN")
Julio Rodriguez
ETL Developer by choice
"Sure we have lots of reasons for being rude - But no excuses
ETL Developer by choice
"Sure we have lots of reasons for being rude - But no excuses
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Ah... the Masked Decimal conversions. They're not really all that well explained in the docs, you mostly have to infer how they work from the examples they include. What exactly does "MD2-" mean? A scale of two with a trailing minus sign?
-craig
"You can never have too many knives" -- Logan Nine Fingers
"You can never have too many knives" -- Logan Nine Fingers
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
They are explained well in the UniVerse docs. "MD2-" indicates two decimal places with a trailing sign. Note, though, that the result of Iconv() has masked decimal - to reinstate you would need an Oconv().
Code: Select all
Oconv(Iconv(InLink.TheValue, "MD2-"), "MD2")
Last edited by ray.wurlod on Wed Apr 15, 2009 4:01 pm, edited 1 time in total.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.