February 2019
Intermediate to advanced
626 pages
15h 51m
English
While PowerShell itself comes with reasonably basic mathematical operators, the .NET System.Math class 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)
By default, the Round method in .NET performs what's known as bankers rounding. It will always prefer to round to an even number. For example, 1.5 will round to 2, and 2.5 will round to 2.
This behavior can be changed using the MidpointRounding enumeration, as shown here:
[Math]::Round(2.225, 2) # Results in 2.22[Math]::Round(2.225, 2, [MidpointRounding]::AwayFromZero) # Results in 2.23
The Ceiling and Floor methods ...
Read now
Unlock full access