The Nth of N
May 7th, 2006
English has some varying postfixes to numbers. Most end with a "th" - tenth, fifteenth, one-thousand-and-ninty-eighth - but a few number do not. I think I’ve caught all the rules here.
function postfixer($number) {
switch($number % 100) {
case 11: return $number . "th"; break;
case 12: return $number . "th"; break;
case 13: return $number . "th"; break;
}
switch($number % 10) {
case 1: return $number . "st"; break;
case 2: return $number . "nd"; break;
case 3: return $number . "rd"; break;
default: return $number . "th"; break;
}
}
Shortly after writing this code, I was remined of the score - a quantity of twenty (Americans should know “Four score and seven years ago” from their history books) - that also effects the french system of numbers.
For example, the number 92 would be said quatre-vingt-douze. Literally, this translates as four-twenties-and-twelve, or, if you prefer, four-score-and-twelve. There are other wierdnesses, but this is the most literal.
I should add that this doesn’t really apply to the code above. The numbers 11, 12, and 13 are unique in being quantified with “-th”.
-Sud.
Posted in Overanalytical, PHP |