Dividing '-20' by '-10' gives me 2, as i needed '-2'
Moderators: chulett, rschirm, roy
Dividing '-20' by '-10' gives me 2, as i needed '-2'
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
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
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.
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
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
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
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
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
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
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.ray.wurlod wrote:Code: Select all
If Divisor = 0 Then 0 Else Abs(Dividend/Divisor)
Thanks
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Hi Kcbland,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)
I got the result i wanted with the above code. Thanks a lot.