View Single Post
KyleS
SourceMod Plugin Approver
Join Date: Jul 2009
Location: Segmentation Fault.
Old 02-19-2017 , 19:52   Re: [ANY] Singular and Plural
Reply With Quote #6

Quote:
Originally Posted by Chdata View Post
Code:
//  Evaluates to a string of the ordinal suffix of a number (1st, 2nd, 3rd, etc)
#define NatSuf(%1)               ((%1 + 9) % 10 >= 3 || (%1 + 89) % 100 < 3 ? "th" : (%1 % 10) == 1 ? "st" : (%1 % 10) == 2 ? "nd" : "rd")
Ah yes, the 0th

Instead of going into macro, modulo, and ternary hell, try something untested like this:
PHP Code:
static stock NatStuf(number)
{
    static const 
String:InternalPrefix[][] = {"""st""nd""rd""th"};
    new 
mod = (number 10);
    if (
mod 3)
        
mod = (sizeof(InternalPrefix) - 1);
    
    return 
_:InternalPrefix[mod];

KyleS is offline