On this page:
~r*
ordinal
8.18.0.15

4 Formatting🔗

 (require toolbox/format) package: toolbox-lib

procedure

(~r* x    
  [#:sign sign    
  #:base base    
  #:precision precision    
  #:notation notation    
  #:format-exponent format-exponent    
  #:min-width min-width    
  #:pad-string pad-string    
  #:groups groups    
  #:group-sep group-sep    
  #:decimal-sep decimal-sep])  string?
  x : rational?
  sign : 
(or/c #f '+ '++ 'parens
      (let ([ind (or/c string? (list/c string? string?))])
        (list/c ind ind ind)))
   = #f
  base : (or/c (integer-in 2 36) (list/c 'up (integer-in 2 36)))
   = 10
  precision : 
(or/c exact-nonnegative-integer?
      (list/c '= exact-nonnegative-integer?))
 = 6
  notation : 
(or/c 'positional 'exponential
      (-> rational? (or/c 'positional 'exponential)))
   = 'positional
  format-exponent : (or/c #f string? (-> exact-integer? string?))
   = #f
  min-width : exact-positive-integer? = 1
  pad-string : non-empty-string? = " "
  groups : (non-empty-listof exact-positive-integer?) = '(3)
  group-sep : string? = ","
  decimal-sep : string? = "."
Like ~r from racket/format, except that the default value of group-sep is "," instead of "", so numbers include thousands separators by default.

procedure

(ordinal n [#:word? use-word?])  string?

  n : exact-nonnegative-integer?
  use-word? : any/c = #f
Returns an ordinal numeral for n.

Examples:
> (ordinal 1)

"1st"

> (ordinal 2)

"2nd"

> (ordinal 23)

"23rd"

If use-word? is not #f, then a word will be returned instead of a numeral with a suffix if n is between 1 and 10, inclusive.

Examples:
> (ordinal 1 #:word? #t)

"first"

> (ordinal 2 #:word? #t)

"second"

> (ordinal 10 #:word? #t)

"tenth"

> (ordinal 11 #:word? #t)

"11th"