Get Ordinal Suffix
Returns the ordinal suffix for a given number or numeric string.
getOrdinal
The getOrdinal function returns the ordinal suffix (e.g., 'st', 'nd', 'rd', 'th') for a given number or numeric string. It optionally prefixes the suffix with the original number (e.g., "1st" or "st").
Function Signature
function getOrdinal(num: Numeric, withNumber?: boolean): stringParameters
num(Numeric): The number (or numeric string) to derive the ordinal suffix from.withNumber(optional,boolean): Iftrue, returns the number with its ordinal suffix (e.g.,"3rd"). Iffalse, returns only the suffix (e.g.,"rd"). Defaults totrue.
Return Value
string:- The number concatenated with its ordinal suffix (e.g.,
"1st","2nd") ifwithNumberistrue. - Only the suffix (e.g.,
"th","nd") ifwithNumberisfalse.
- The number concatenated with its ordinal suffix (e.g.,
Example Usage
playground.ts
Notes
- Handles special cases for numbers ending in
11,12, or13(all use'th'). - Negative numbers are treated as their absolute values (e.g.,
-5→"5th").
Types
Numeric
type Numeric = number | `${number}`;Aliases
cardinalToOrdinalconvertNumberToOrdinalconvertToOrdinalgetOrdinalNumbernumberToOrdinal
Last updated: Sun, Jun 14, 2026 07:06:16AM (UTC)
