ColdFusion Add ordinal suffix to a number

Other languages include this functionality as part of their date formatting functions.  ColdFusion, for some reason, does not.

Either way, you may need to add an ordinal suffix to the a non-date related number.
<cfset thenumber = [WHATEVER YOUR NUMBER IS]>

<cfswitch expression="#thenumber Mod 10#">
	<cfcase value="1">
		<cfset thenumber = thenumber & "st">
	<cfcase value="2">
		<cfset thenumber  = thenumber  & "nd">
	<cfcase value="3">
		<cfset thenumber  = thenumber & "rd">
		<cfset thenumber = thenumber  & "th">
Posted by
Snippet Viewed 5618 times.

Share your ColdFusion code snippets:

  • Get some recognition & link back to your site.


Submit | Browse

Most Recent coldfusion snippets

Most Viewed