Created
November 18, 2015 15:46
-
-
Save lazywinadmin/b4e77c305d47878381d7 to your computer and use it in GitHub Desktop.
Add a String method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$a = 1257657656 | |
$a = $a | Add-Member -MemberType ScriptMethod -Name tostring -Force -Value { param($Unit = 1MB, $Digits =1, $Suffix=' MB') "{0:n$Digits}$Suffix" -f ($this/($Unit)) } -PassThru | |
<# | |
PS> $a | |
1.199,4 MB | |
PS> $a.ToString(1GB, 0, ' GB') | |
1 GB | |
PS> $a.ToString(1KB, 2, ' KB') | |
1.228.181,30 KB | |
PS> $a -eq 1257657656 | |
True | |
PS> $a -eq 1257657657 | |
False | |
PS> $a.GetType().Name | |
Int32 | |
#> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment