- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use PowerShell as a Calculator? Or How to use PowerShell for arithmetic operations?
You can use the PowerShell console to perform arithmetic operations, the same way the calculator does.
To do the addition operation,
2+3
Output − 5
For complex, additional operations as well it is too quick.
10024455 + 554668 + 9964455
Output − 20543578
Floating numbers operation,
5569899.65 + 554886.32
Output − 6124785.97
To perform subtract operation,
55564488556 - 55141256665
Output − 423231891
With Integer and floating number subtraction,
5569899 - 554886.32
Output − 5015012.68
Divide Operation,
556989 / 554
Output − 1005.39530685921
Multiplication operation,
5533 * 445
Output − 2462185
Multiple Operations,
(445 + 5443) * 332 / 32
Output − 61088
When you perform any arithmetic operation, when values separated by command, it will give the wrong values. For example,
5,4 + 2
Output −
5 4 2
The above output is wrong because the comma(,) creates an array.
Powershell also works with Units like MB, GB, and KB. When you specify number and unit, there should not be space in between them. For example, 12mb is valid but 12 mb is invalid. It is case insensitive, so you can use MB or mb, GB or gb or KB or kb.
1gb / 1mb
Output − 1024
2gb * 6
Output − 12884901888
5GB - 2GB
Output − 3221225472
PowerShell also understands the hexadecimal values.
15 + 0xAF
Output − 190
0xAFF
Output − 2815
- Related Articles
- How to use a transcript in PowerShell?
- How to use PowerShell Help commands?
- How to use stopwatch in PowerShell?
- How to use PowerShell break statement with the For loop?
- How to use an alias() for the parameter in PowerShell?
- How to use Measure-Object in PowerShell?
- How to use Wait-Process in Powershell?
- How to use Hashtable splatting in PowerShell?
- How to use Array Splatting in PowerShell?
- How to use function Alias in PowerShell?
- How to use Compare-Object in PowerShell?
- How to use -For parameter in Restart-Computer cmdlet in PowerShell?
- How to use PowerShell Break with the Label.
- How to use Group-Object cmdlet in PowerShell?
- How to use the ErrorActionPreference variable in PowerShell?
