N'th: Difference between revisions
Content added Content deleted
(→{{header|Batch File}}: Fixed 11tth, 12th and 13th) |
(→{{header|PowerShell}}: Fixed 11th, 112th and 13th) |
||
Line 3,207: | Line 3,207: | ||
=={{header|PowerShell}}== |
=={{header|PowerShell}}== |
||
<syntaxhighlight lang="powershell"> |
<syntaxhighlight lang="powershell"> |
||
function nth($inp){ |
|||
$suffix = "th" |
|||
switch($inp % 100){ |
|||
11{$suffix="th"} |
|||
12{$suffix="th"} |
|||
13{$suffix="th"} |
|||
default{ |
|||
} |
|||
switch($inp % 10){ |
|||
⚫ | |||
1{$suffix="st"} |
|||
2{$suffix="nd"} |
|||
3{$suffix="rd"} |
|||
} |
|||
⚫ | |||
} |
|||
⚫ | |||
} |
} |
||
0..25 | %{Write-host -nonewline (nth "$_")};"" |
0..25 | %{Write-host -nonewline (nth "$_")};"" |
||
250..265 | %{Write-host -nonewline (nth "$_")};"" |
250..265 | %{Write-host -nonewline (nth "$_")};"" |
||
1000..1025 | %{Write-host -nonewline (nth "$_")};"" |
1000..1025 | %{Write-host -nonewline (nth "$_")};"" |
||
</syntaxhighlight> |
|||
{{Out}} |
{{Out}} |
||
<pre> |
|||
0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th |
|||
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th |
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th |
||
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th |
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th |
||
</pre> |
|||
===An Alternate Version=== |
===An Alternate Version=== |
||
Line 3,233: | Line 3,244: | ||
$suffix = "th" |
$suffix = "th" |
||
switch ($Number % |
switch ($Number % 100){ |
||
11 {$suffix = "th"} |
|||
⚫ | |||
12 {$suffix = "th"} |
|||
13 {$suffix = "th"} |
|||
default { |
|||
switch ($Number % 10){ |
|||
1 {$suffix = "st"} |
|||
2 {$suffix = "nd"} |
|||
3 {$suffix = "rd"} |
|||
} |
|||
} |
|||
} |
} |
||
Line 3,249: | Line 3,266: | ||
{{Out}} |
{{Out}} |
||
<pre> |
<pre> |
||
1st |
1st 2nd 3rd 4th 5th |
||
6th |
6th 7th 8th 9th 10th |
||
11th 12th 13th 14th 15th |
|||
16th |
16th 17th 18th 19th 20th |
||
21st |
21st 22nd 23rd 24th 25th |
||
251st |
251st 252nd 253rd 254th 255th |
||
256th |
256th 257th 258th 259th 260th |
||
261st |
261st 262nd 263rd 264th 265th |
||
1001st |
1001st 1002nd 1003rd 1004th 1005th |
||
1006th |
1006th 1007th 1008th 1009th 1010th |
||
1011th 1012th 1013th 1014th 1015th |
|||
1016th |
1016th 1017th 1018th 1019th 1020th |
||
1021st |
1021st 1022nd 1023rd 1024th 1025th |
||
</pre> |
</pre> |
||