Skip to content

Give ordinal of a whole float the same suffix as its string form - #291

Open
FatmaMahmoudR wants to merge 1 commit into
jaraco:mainfrom
FatmaMahmoudR:fix-ordinal-floats-192
Open

FatmaMahmoudR wants to merge 1 commit into
jaraco:mainfrom
FatmaMahmoudR:fix-ordinal-floats-192

Conversation

@FatmaMahmoudR

Copy link
Copy Markdown
Contributor

Closes #192.

ordinal takes the suffix of a decimal number from its last digit, so ordinal("1.0") is "1.0th". A float holding a whole number went down a separate path that used its integer value instead:

>>> p.ordinal("1.0")
'1.0th'
>>> p.ordinal(1.0)  # before
'1.0st'
>>> p.ordinal(2.0)  # before
'2.0nd'

Now any number with a decimal point uses its last digit, so ordinal(1.0) == ordinal("1.0") == "1.0th", the same way the existing test has ordinal(1.1) == ordinal("1.1"). A float's ordinal now always matches its string's, including large floats Python writes in scientific notation, such as 1.1e+21.

For the other case in the issue, ordinal("1."), there's no digit after the point to take the suffix from, so it now raises BadNumValueError instead of returning "1.st". If you'd rather keep "1.st", I can put that branch back.

With both special cases gone, the branching in ordinal comes down to one line.

@FatmaMahmoudR
FatmaMahmoudR marked this pull request as ready for review October 22, 2026 15:30
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.

Broken ordinal cases

1 participant