<cfset thenumber = [WHATEVER YOUR NUMBER IS]>
<cfswitch expression="#thenumber Mod 10#">
<cfcase value="1">
<cfset thenumber = thenumber & "st">
</cfcase>
<cfcase value="2">
<cfset thenumber = thenumber & "nd">
</cfcase>
<cfcase value="3">
<cfset thenumber = thenumber & "rd">
</cfcase>
<cfdefaultcase>
<cfset thenumber = thenumber & "th">
</cfdefaultcase>
</cfswitch>
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.
Snippet Viewed 5618 times.
Share your ColdFusion code snippets:
- Get some recognition & link back to your site.
Related Articles