if (n % 10 == 1 && n % 100 != 11) suffix = "st";
else if (n % 10 == 2 && n % 100 != 12) suffix = "nd";
else if (n % 10 == 3 && n % 100 != 13) suffix = "rd";
else suffix = "th";
取模(餘數)運算**:`n % 10` 回傳 `n` 除以 10 的餘數,即 **個位數字**。
英文**序數詞**尾綴:
| 基數 | 序數 | 縮寫 | 規則 |
|---|---|---|---|
| one | first | 1st | 個位 1,但 11 例外 |
| two | second | 2nd | 個位 2,但 12 例外 |
| three | third | 3rd | 個位 3,但 13 例外 |
| four~ | fourth~ | 4th~ | 其餘皆 th |
英語中 **11, 12, 13(及 111, 112, 113...)是特例**,統一用 `th`:
1 → 1st
2 → 2nd
3 → 3rd
4 → 4th
11 → 11th (例外)
12 → 12th (例外)
13 → 13th (例外)
21 → 21st
22 → 22nd
23 → 23rd
111 → 111th (例外)
`%10` 取個位數字;`st/nd/rd` 對應 first/second/third 縮寫;`11/12/13` 為語言學例外需額外排除。此邏輯常用於日期顯示(1st Jan)、排名列表、頁碼等國際化場景。