PowerShell Numbers
A number is a value you can count and calculate with. PowerShell adds, subtracts, multiplies, and divides numbers with simple symbols.
Add and subtract
The plus sign adds and the minus sign subtracts. Store each answer in a variable and print it.
$sum = 4 + 5
$sum
$left = 10 - 3
$leftDivide and find the remainder
Division can give a decimal answer. The percent sign gives the remainder instead.
$half = 7 / 2
$half
$left = 7 % 2
$leftGroup with parentheses
Parentheses group a calculation that runs first. Without them the multiplication would run first.
$result = (2 + 3) * 4
$resultExample
$books = 3
$bookPrice = 12
$total = $books * $bookPrice
$total
$change = 50 - $total
$changeKey points
- Addition: use the plus sign to add numbers.
- Subtraction: use the minus sign to subtract numbers.
- Multiplication: use the star symbol to multiply numbers.
- Division: use the slash symbol to divide numbers. Division can give a decimal answer.
- Remainder: use the percent sign to find what is left after division.
- Parentheses: use parentheses to group a calculation that runs first.
In this example, the first two lines store a book count and a book price. The third line multiplies them to get the total. The last two lines print the total and the change from 50.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
What is the value of 7 % 2?