January 27th, 2015

PowerTip: Use Parentheses to Override Operator Precedence

Doctor Scripto
Scripter

Summary: Use parentheses to override operator precedence in Windows PowerShell.

Hey, Scripting Guy! Question How can I ensure that a math expression that keeps returning incorrect information will work properly in
           Windows PowerShell?                                               

Hey, Scripting Guy! Answer In Windows PowerShell (as in other languages), math operators have a precedence. Therefore, division
           comes before addition. If you want to override this behavior, group with parentheses, for example:

PS C:\> 2 + 9 / 3

(2 + 9)/3

5

3.66666666666667

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.