How to use PowerShell as a Calculator? Or How to use PowerShell for arithmetic operations?

PowerShellMicrosoft TechnologiesSoftware & Coding

  • 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

raja
Published on 14-Feb-2020 11:44:51
Advertisements