Quantcast
Channel: Hey, Scripting Guy! Blog
Viewing all articles
Browse latest Browse all 3333

PowerTip: Use Parentheses to Override Operator Precedence

$
0
0

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


Viewing all articles
Browse latest Browse all 3333

Trending Articles