PowerTip: Use Parentheses to Override Operator Precedence

Doctor Scripto

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




Discussion is closed.

Feedback usabilla icon