G.STNDRD
From GMod Wiki
Function | |
Syntax |
STNDRD( Number number ) Where is this used? |
Description: | |
Returns the proper suffix for a number between 0 and 20. | |
Returns: | String st nd rd th |
Part of Library: | Global Functions |
Realm: | |
BBCode Link: | [b][url=http://wiki.garrysmod.com/?title=G.STNDRD]G.STNDRD [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] |
Examples
Implementation
function STNDRD( num ) if ( num == 1 ) then return "st" end if ( num == 2 ) then return "nd" end if ( num == 3 ) then return "rd" end return "th" end
Fix
function STNDRD( num ) if ( num > 3 and num < 21 ) then return "th" local n = num % 10 elseif ( n == 1 ) then return "st" elseif ( n == 2 ) then return "nd" elseif ( n == 3 ) then return "rd" end return "th" end
Notes
- Only works up to 20. Values such as 21, 22, 23 will incorrectly return "th".