/** * produces an ordinal "th" suffix string for given number. * @param number value you want the ordinal suffix for: * @return corresponding ordinal suffix, i.e. "st", "nd", "rd", or "th" */ String ordinalSuffix ( int value ) { value = Math.abs( value ); final int lastDigit = value % 10; final int last2Digits = value % 100; switch ( lastDigit ) { case 1 : return last2digits == 11 ? "th" : "st"; case 2: return last2digits == 12 ? "th" : "nd"; case 3: return last2digits == 13 ? "th" : "rd"; default: return "th"; } }