Welcome, Guest. Please Login
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
Pages: 1
Send Topic Print
Adding (English) number suffixes: '2nd', etc. (Read 1627 times)
Mark Anderson
YaBB Administrator

User - not staff!

Posts: 5689
Southsea, UK
Adding (English) number suffixes: '2nd', etc.
Apr 2nd, 2013, 6:56am
Researching issues raised (in another thread) about removing number suffixes, e.g. "3rd" -> "3", I tripped across a neat solution** to adding such suffixes.

Add a List and Number attribute and try this code, as a stamp or $Rule or in some such context;

$MyList = "th;st;nd;rd;th;th;th;th;th;th";
if (mod($MyNum,100) >= 11 & mod($MyNum,100) <= 13) {
  $MyString = $MyNum + "th";
} else {
  $MyString = $MyNum + $MyList.at(mod($MyNum,10));

Of course for languages other than English not only the suffixes will differ but the logic will likely change too.

** kudos: this stackoverflow thread.
Back to top
« Last Edit: Apr 02nd, 2013, 9:30am by Mark Anderson »  

Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Pages: 1
Send Topic Print