Convert number to ordinal number notation
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Ordinal number for Emacs Lisp

MELPA: ordinal MELPA stable: ordinal

This package simply provides conversion to English ordinal numbers. (ex. 1st, 2nd, 3rd, 4thNth)


Function string ordinal-format (integer N)

Return string with an English ordinal appended to an integer N.

(ordinal-format 0) ; => "0th" but, it's not strictly correct English
(ordinal-format 1) ; => "1st"
(ordinal-format 2) ; => "2nd"
(ordinal-format 3) ; => "3rd"
(ordinal-format 4) ; => "4th"

(ordinal-format -1)
;; => Assertion failed: (>= n 0)

Variable boolean ordinal-number-accept-0 (default: T)

When this variable is non-~NIL~, 0th is not allowed.

(let ((ordinal-number-accept-0 nil))
  (ordinal-format 0))
;; => Assertion failed: (>= n 1)

This variable works with dynamic scope. Do not use setq for ordinal-number-accept-0.

Function string ordinal-suffix (integer N)

This is a function to convert the number suffix. Please be careful that it will not check the lower limit.

(ordinal-suffix 1)  ; => "st"
(ordinal-suffix 2)  ; => "nd"
(ordinal-suffix 3)  ; => "rd"
(ordinal-suffix 4)  ; => "th"
(ordinal-suffix 0)  ; => "th"
(ordinal-suffix -1) ; => "th"

That is, (ordinal-suffix -1) is a valid expression.