How do I take the integer value of a number?
There are 2 ways to cast PowerShell, one is a direct type cast, and the other is a conversion via the-as operator
- PS f:\> [int] (3/2) # Direct Type casts
- 2
- PS f:\> (3/2)-as [int] #-as operator for type conversion
- 2
- PS f:\>
The result of the cast is rounded.
Now we need to find another way to solve the problem: Take "Max integer" with "not greater than value"
Use ". NET class, the "floor method" in the "math class" can be implemented
- PS f:\> [Math]::floor (3/2)
- 1
However, this method is only valid for positive numbers. If it is a negative number, use [math]::ceiling ] to take the smallest integer not less than the value of the parameter.
- PS f:\> [Math]::ceiling ( -3/2)
- -1
$size = ("{0:n2}"-F ($subFolderItems. SUM/1GB)) Keep two digits after the decimal point
$size =[math]::truncate ($disk. SIZE/1GB) to intercept the decimal point, preserving the integer
$size = ("{0:n2}"-F ($subFolderItems. SUM/1GB)) Keep two digits after the decimal point
$size =[math]::truncate ($disk. SIZE/1GB) to intercept the decimal point, preserving the integer
Powershell&. NET Numeric rounding Processing