Skip to content

[12.x] - Add Str::ordinal() helper method to return ordinal suffixes for numbers #56008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

semernur
Copy link

This PR adds a new Str::ordinal() helper method to return the ordinal representation of a number (e.g., 1st, 2nd, 3rd, etc.).

Example

Str::ordinal(1);   // "1st"
Str::ordinal(2);   // "2nd"
Str::ordinal(3);   // "3rd"
Str::ordinal(11);  // "11th"
Str::ordinal(21);  // "21st"

@Seb33300
Copy link

The implementation should support different languages, such as the Str::plural() helper method.

In french:

Str::ordinal(1);   // "1er" (or "1re" if female)
Str::ordinal(2);   // "2e"
Str::ordinal(3);   // "3e"
Str::ordinal(11);  // "11e"
Str::ordinal(21);  // "21e"

@Seb33300
Copy link

Seb33300 commented Jun 12, 2025

Just found that a Number::spellOrdinal() already exist in the Number helper.

So your helper should probably be moved to the Number class next to the existing one.

@semernur
Copy link
Author

semernur commented Jun 12, 2025

Just found that a Number::spellOrdinal() already exist in the Number helper.

So your helper should probably be moved to the Number class next to the existing one.

Matter of fact, the ordinal helper is already there inside the Number class, Lol.

@semernur semernur closed this Jun 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants