Toolbox-XToolbox-X

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): string

Parameters

  • num (Numeric): The number (or numeric string) to derive the ordinal suffix from.
  • withNumber (optional, boolean): If true, returns the number with its ordinal suffix (e.g., "3rd"). If false, returns only the suffix (e.g., "rd"). Defaults to true.

Return Value

  • string:
    • The number concatenated with its ordinal suffix (e.g., "1st", "2nd") if withNumber is true.
    • Only the suffix (e.g., "th", "nd") if withNumber is false.

Example Usage

playground.ts

Notes

  • Handles special cases for numbers ending in 11, 12, or 13 (all use 'th').
  • Negative numbers are treated as their absolute values (e.g., -5"5th").

Types

Numeric

type Numeric = number | `${number}`;

Aliases

  • cardinalToOrdinal
  • convertNumberToOrdinal
  • convertToOrdinal
  • getOrdinalNumber
  • numberToOrdinal

Last updated: Sun, Jun 14, 2026 07:06:16AM (UTC)

On this page