Page 1 of 1

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

Posted: Tue Feb 28, 2006 3:37 pm
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

Posted: Tue Feb 28, 2006 3:50 pm
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.

Posted: Tue Feb 28, 2006 4:06 pm
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

Posted: Tue Feb 28, 2006 4:13 pm
by ray.wurlod

Code: Select all

If Divisor = 0 Then 0 Else Abs(Dividend/Divisor)

Posted: Tue Feb 28, 2006 4:27 pm
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)

Posted: Tue Feb 28, 2006 4:36 pm
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

Posted: Tue Feb 28, 2006 4:43 pm
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)

Posted: Tue Feb 28, 2006 4:47 pm
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.