0

我正在使用以下代码检索序数:

public static String ordinal(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];

    }
}

输出:第一,第二,第三...

如何从 java、Android 中的这些序数中获取第一个、第二个、第三个字符串。

4

1 回答 1

3

你可以使用我写的这个类。只需将文件(包括许可证头)下载到您的项目中,更新包声明,您就可以像这样使用它。

Numerals ns = new Numerals();
System.out.println(ns.toWords(12048));
System.out.println(ns.toWords(12048, true));
System.out.println(ns.toWords(102500, false));
System.out.println(ns.toWords(102500, true));

哪个输出

12048
1204810205512005
_
_

的第二个参数toWords(如果指定)确定是输出序数 (true) 还是常规数字 (false)。你可以看看它,看看它是如何工作的。

于 2017-12-15T17:33:46.743 回答