Return a positive integer combined with its English ordinal suffix (st, nd, rd, th). Numbers whose last two digits are 11, 12, or 13 always take "th". Otherwise numbers ending in 1 take "st", 2 take "nd", 3 take "rd", and all others take "th". Return null for null input.
Examples:
Input: n = 1
Output: '1st'
Explanation: Last digit is 1 and last two digits are not 11, so suffix is st
Input: n = 22
Output: '22nd'
Explanation: Last digit is 2 and last two digits are not 12, so suffix is nd
Input: n = 13
Output: '13th'
Explanation: Last two digits are 13, so suffix is always th
Input: n = 103
Output: '103rd'
Explanation: Last digit is 3 and last two digits are not 13, so suffix is rd
Input: n = 111
Output: '111th'
Explanation: Last two digits are 11, so suffix is always th
Apex Code Editor
Welcome to Lightning Challenge!
How It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay September 2026 (Sep 1–15)Sponsored by FLXBL
Contest runs September 1 - 15. Complete challenges to climb the leaderboard!
1st & 2nd: Salesforce certification exam voucher — see all prizes
Only the 15 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.