Public/Get-OrdinalNumber.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
function Get-OrdinalNumber { [CmdletBinding()] [OutputType([string])] PARAM ( [Parameter(Mandatory=$true, ValueFromPipeline=$true)][int]$Number ) process { [int]$ModHundred = $Number % 100 [int]$ModTen = $Number % 10 [string]$Suffix = 'th' if($ModHundred -gt 20 -or $ModHundred -lt 10) { switch($ModTen) { 1 { $Suffix = 'st' } 2 { $Suffix = 'nd' } 3 { $Suffix = 'rd' } } } "$Number$Suffix" } } |