October 2017
Intermediate to advanced
440 pages
11h 47m
English
While PowerShell itself comes with reasonably basic mathematical operators, the .NET class System.Math has a far wider variety.
The Round static method can be used to round up to a fixed number of decimal places. In the following example, the value is rounded to two decimal places:
[Math]::Round(2.123456789, 2)
The Ceiling and Floor methods are used when performing whole-number rounding:
[Math]::Ceiling(2.1234) # Returns 3 [Math]::Floor(2.9876) # Returns 2
The Abs converts a positive or negative integer to a positive integer (multiplies by -1 if the value is negative):
[Math]::Abs(-45748)
Numbers may be raised to a power:
[Math]::Pow(2, 8) # Returns 256 (28)
A square root can be calculated:
[Math]::Sqrt(9) # Returns ...
Read now
Unlock full access