Dividing '-20' by '-10' gives me 2, as i needed '-2'

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
iwin
Premium Member
Premium Member
Posts: 99
Joined: Mon Apr 11, 2005 9:20 pm

Dividing '-20' by '-10' gives me 2, as i needed '-2'

Post by iwin »

Hi,
I am trying to divide -20 by -10 and i need the result to be -2 as i am calculating %. But it is giving me 2. Please let me know what function should i use.

Thanks in advance
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

You get 2 because the laws of mathematics dictates that is the answer. Two negative numbers multiplied together always produce a positive, and division is the same.

If you don't like your answer, just multiply by -1 whenever you need to change polarity.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
iwin
Premium Member
Premium Member
Posts: 99
Joined: Mon Apr 11, 2005 9:20 pm

Post by iwin »

kcbland wrote:You get 2 because the laws of mathematics dictates that is the answer. Two negative numbers multiplied together always produce a positive, and division is the same.

If you don't like your answer, just multiply by -1 whenever you need to change polarity.

Hi,

Thanks for the reply. Actually i have two columns A and B and i need to find C which is A percent of B. and if A and B are +ve then then C is +ve but if A and B are -ve then the result C should also be -ve. Can you tell help me how to code it.

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

Post by ray.wurlod »

Code: Select all

If Divisor = 0 Then 0 Else Abs(Dividend/Divisor)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Per the user's requirement, the polarity of the percentage doesn't matter:

Code: Select all

If Divisor = 0 Then 0 Else Dividend/ABS(Divisor)
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
iwin
Premium Member
Premium Member
Posts: 99
Joined: Mon Apr 11, 2005 9:20 pm

Post by iwin »

ray.wurlod wrote:

Code: Select all

If Divisor = 0 Then 0 Else Abs(Dividend/Divisor)
Thanks for the reply ray. But i think my question is not clear. Actually what i am trying to do is divide A by B such that if A and B are both -ve then the result should be a -ve value and if A is -ve and B is +ve or A is +ve and B is -ve then the result value should be -ve value. And if both A and B are both +ve then the result should be a +ve value.

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

Post by ray.wurlod »

Code: Select all

If Divisor = 0 Then 0 Else Abs(Dividend/Divisor) * ((If Dividend > 0 And Divisor > 0) Then 1 Else -1)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
iwin
Premium Member
Premium Member
Posts: 99
Joined: Mon Apr 11, 2005 9:20 pm

Post by iwin »

kcbland wrote:Per the user's requirement, the polarity of the percentage doesn't matter:

Code: Select all

If Divisor = 0 Then 0 Else Dividend/ABS(Divisor)
Hi Kcbland,
I got the result i wanted with the above code. Thanks a lot.
Post Reply