Skip to content

Instantly share code, notes, and snippets.

@pfmiles
Created August 18, 2016 09:26
Show Gist options
  • Save pfmiles/bf91f7cb26ffdba3f17732f76411c153 to your computer and use it in GitHub Desktop.
Save pfmiles/bf91f7cb26ffdba3f17732f76411c153 to your computer and use it in GitHub Desktop.
将数字变为“1st/2nd/3rd/4th...”这种表示”顺序“的形式
/**
* 将数字变为“1st/2nd/3rd/4th...”这种表示”顺序“的形式
*/
public static String toOrdinal(int i) {
String[] sufixes = new String[] { "th", "st", "nd", "rd", "th", "th", "th", "th", "th",
"th" };
switch (i % 100) {
case 11:
case 12:
case 13:
return i + "th";
default:
return i + sufixes[i % 10];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment