Created
August 18, 2016 09:26
-
-
Save pfmiles/bf91f7cb26ffdba3f17732f76411c153 to your computer and use it in GitHub Desktop.
将数字变为“1st/2nd/3rd/4th...”这种表示”顺序“的形式
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 将数字变为“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