ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Need explanation on operator precedence (https://www.excelbanter.com/excel-discussion-misc-queries/77674-need-explanation-operator-precedence.html)

SFH

Need explanation on operator precedence
 

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

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

but i tried to experiment using the following:

*=IF(B510000,B5*50%,IF(*10000B50*,B5*25%,"No Tax")) *----this
works,displays 1125

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

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


--
SFH
------------------------------------------------------------------------
SFH's Profile: http://www.excelforum.com/member.php...o&userid=32512
View this thread: http://www.excelforum.com/showthread...hreadid=522999



Need explanation on operator precedence
 
Hi

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

Hope this helps.
Andy.

"SFH" wrote in message
...

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

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

but i tried to experiment using the following:

*=IF(B510000,B5*50%,IF(*10000B50*,B5*25%,"No Tax")) *----this
works,displays 1125

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

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


--
SFH
------------------------------------------------------------------------
SFH's Profile:
http://www.excelforum.com/member.php...o&userid=32512
View this thread: http://www.excelforum.com/showthread...hreadid=522999




[email protected]

Need explanation on operator precedence
 
"SFH" wrote:
can anyone please explain to me the operator precedence
rule in this formula :
[....]
=IF(B510000,B5*50%,IF(10000B50,B5*25%,"No Tax"))
----this works,displays 1125
=IF(B510000,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(!).


vezerid

Need explanation on operator precedence
 
Jumping in to clarify something in joeu's explanation:

10000B50 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 TrueFalse. Thus:

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

HTH
Kostis Vezerides


[email protected]

Need explanation on operator precedence
 
"vezerid" wrote:
Jumping in to clarify something in joeu's explanation:
10000B50 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.


SFH

Need explanation on operator precedence
 

thank you to all of you for clarifying the question i asked. Thanks for
your time and help.

Hana
Singapore


--
SFH
------------------------------------------------------------------------
SFH's Profile: http://www.excelforum.com/member.php...o&userid=32512
View this thread: http://www.excelforum.com/showthread...hreadid=522999



All times are GMT +1. The time now is 08:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com