Need explanation on operator precedence

  • Thread starter Thread starter SFH
  • Start date Start date
S

SFH

hi can anyone please explain to me the operator precedence rule in thi
formula :

This formula works as what i wanted:
=IF(B5>10000,D5*50%,IF(B5>0,D5*25%,\"NO TAX\")
The above is the correct formula, my b5=4500, so my answer is 1125. Th
formula works.

but i tried to experiment using the following:

*=IF(B5>10000,B5*50%,IF(*10000>B5>0*,B5*25%,"No Tax")) *----thi
works,displays 1125

*
=IF(B5>10000,B5*50%,IF(*0<B5<10000*,B5*25%,"No Tax"))* ----this doesn'
work, displays no tax.

hope someone can explain it to me ..thank you very much. i know this i
something about precedence but i need more details about this
 
Hi

If you want more than one test within an IF formula, use AND() or OR(). For
example:
=IF(B5>10000,B5*50%,IF(AND(B5>0,B5<10000),B5*25%,"No Tax"))

Hope this helps.
Andy.
 
SFH said:
can anyone please explain to me the operator precedence
rule in this formula :
[....]
=IF(B5>10000,B5*50%,IF(10000>B5>0,B5*25%,"No Tax"))
----this works,displays 1125
=IF(B5>10000,B5*50%,IF(0<B5<10000*,B5*25%,"No Tax"))
----this doesn't work, displays no tax.

Someone else answered the "real" question, namely: what
is the correct way to express "a > b > c". But to answer your
question ....

The first case is evaluated as "(10000 > B5) > 0".
"(10000 > B5)" results in a boolean value of true or false,
which has a numerical value of 1 or 0 respectively. Therefore,
the expression becomes "1 > 0" or "0 > 0", which coincidentally
is true or false when "(10000 > B5)" is true or false. But note
that this does behave as you intended when B5 <= 0. In that
case "10000 > B5 > 0" will be true(!).

The second case is evaluated as "(0 < B5) < 10000".
"(0 < B5)" results in true (1) or false (0). So the expression
becomes "1 < 0" or "0 < 0", which is always false(!).
 
Jumping in to clarify something in joeu's explanation:

10000>B5>0 is indeed first evaluated as (10000 > 85) > 0. However, the
expression in parentheses returns True or False, not 0 or 1. Thus, the
final evaluation compares a T/F with a 1/0.

Excel here provides a two-faced behavior: In *arithetic* expressions,
True is implicitly converted to 1 and False is converted to 0. Yet,
when doing explicit comparison, i.e. in *logical* expressions, True and
False are considered larger than any number and True>False. Thus:

=1<FALSE -------will return TRUE
=FALSE<TRUE --------- will return TRUE

HTH
Kostis Vezerides
 
vezerid said:
Jumping in to clarify something in joeu's explanation:
10000>B5>0 is indeed first evaluated as (10000 > 85) > 0.
However, the expression in parentheses returns True or
False, not 0 or 1. [....] True and False are considered larger
than any number

Thanks for the correction. I admit that I am used to a
reasonable language like C, and I ass-u-me-d that Excel
followed suit.

It's a moot point now, but another comment to correct ....
I wrote: "But note that this does behave as you intended
when B5 <= 0." I meant to write: "does __not__ behave".
But based on vezerid's comment, "(10000 > B5) > 0" does
not even work as you intended when B5 >= 10000.
 
thank you to all of you for clarifying the question i asked. Thanks fo
your time and help.

Hana
Singapor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top