ordinal-suffix ( n -- suffix )


Vocabulary
math.text.english

Inputs
na number


Outputs
suffixa string


Word description
Determine the ordinal suffix for the input number. Non-integral numbers get the ordinal suffix of their integral part.

Examples
USING: kernel math.parser math.text.english prettyprint sequences ; 783 [ number>string ] [ ordinal-suffix ] bi append .
"783rd"


Definition


: ordinal-suffix ( n -- suffix )
abs dup 100 mod 11 13 between?
[ drop "th" ] [
10 mod {
{ 1 [ "st" ] }
{ 2 [ "nd" ] }
{ 3 [ "rd" ] }
[ drop "th" ]
} case
] if ;