Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Page History: Ordinal Function - .NET Framework

Compare Page Revisions



« Older Revision - Back to Page History - Newer Revision »


Page Revision: Fri, Aug 26, 2011, 3:05 PM


See also: Ordinal Function - SQL Server

public static string ToOrdinal(this int input)
{
    var mod100 = input % 100;
    var mod10 = input % 10;
    var result = input.ToString();

    if (mod10 == 1 & mod100 != 11)
        result += "st";
    else if (mod10 == 2 & mod100 != 12)
        result += "nd";
    else if (mod10 == 3 & mod100 != 13)
        result += "rd";
    else
        result += "th";

    return result;
}

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.