January 29th, 2016

PowerTip: Return remainder after dividing two numbers

Doctor Scripto
Scripter

Summary: Use Windows PowerShell to return the remainder after dividing two numbers.

Hey, Scripting Guy! Question How can use Windows PowerShell to divide two numbers and only return the remainder (called a modulo operation)?

Hey, Scripting Guy! Answer In Windows PowerShell, the modulo operator is the % sign. Here are a few examples of how to use it:

PS C:\> 3 % 2

1

PS C:\> 5 % 2

1

PS C:\> 11 % 2

1

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.