Skip to content

fix: use absolute value for Ordinal suffixes - #171

Open
MrBeldum wants to merge 1 commit into
dustin:masterfrom
MrBeldum:fix/ordinal-negative-suffixes
Open

MrBeldum wants to merge 1 commit into
dustin:masterfrom
MrBeldum:fix/ordinal-negative-suffixes

Conversation

@MrBeldum

@MrBeldum MrBeldum commented Oct 5, 2026

Copy link
Copy Markdown

Summary

Ordinal picks st/nd/rd/th with x % 10 / x % 100. In Go the remainder keeps the sign of the dividend, so negatives never hit those cases (-1%10 == -1) and always got "th" (-1th, -21th, -23th).

This change selects the suffix from the absolute value and still formats the original signed integer.

Test plan

  • Extended TestOrdinals with negative cases (-1st, -11th, -21st, …)
  • go test ./...

Go's remainder operator keeps the sign of the dividend, so -1%10 is -1
and never matches the positive cases that choose "st"/"nd"/"rd". Negative
inputs therefore always got a "th" suffix (-1th, -21th, -23th).

Select the suffix from the absolute value while still formatting the
original signed number.

This branch has not been deployed

No deployments
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.

1 participant