Ordinal Numbers β
Use ordinal mode when the UI needs full words like First, Twenty First, or locale-native equivalents instead of suffixes like 1st and 21st.
Basic Usage β
js
import { toOrdinal } from 'to-words';
toOrdinal(1, { localeCode: 'en-US' }); // "First"
toOrdinal(21, { localeCode: 'en-US' }); // "Twenty First"
toOrdinal(1, { localeCode: 'fr-FR' }); // "Premier"
toOrdinal(1, { localeCode: 'es-ES' }); // "Primero"Class API β
js
import { ToWords } from 'to-words';
const tw = new ToWords({ localeCode: 'tr-TR' });
tw.toOrdinal(3);
tw.toOrdinal(12);Per-Locale Imports β
js
import { toOrdinal } from 'to-words/en-US';
toOrdinal(1);
toOrdinal(100);Locale Notes β
- English, Spanish, French, Portuguese, Turkish, and Dutch have explicit ordinal word mappings
- Chinese locales can also use
formal: truefor financial-style ordinal characters - Ordinal conversion expects a non-negative integer input
Common Uses β
- Rankings and leaderboard labels
- Onboarding or checkout step names
- Educational content and voice output
- Report generation where full-word ordinals read better than suffixes