Android examples for java.lang:Integer
get integer Ordinal when converting int to string
import android.content.Context; import android.content.res.AssetManager; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; public class Main{ public static String getOrdinal(int value) { value++; // people start from 1, computers start from zero String suffix = null;/* w w w. j a va 2 s .c o m*/ int lastDigit = value % 10; if (lastDigit == 1) { suffix = "st"; } else if (lastDigit == 2) { suffix = "nd"; } else if (lastDigit == 3) { suffix = "rd"; } else { suffix = "th"; } return Integer.toString(value) + suffix; } }